-
-
Notifications
You must be signed in to change notification settings - Fork 769
🐛 Fix attribute handling in model_dump
for compatibility with the latest Pydantic versions
#1595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…. v2.10 + The else block added to fix linting errors (4b5ad42) for fastapi#1340 was obliterating the 'context' and 'serialize_as_any' attributes for versions >= 2.7 and < 2.11. + Fix by initializing extra_kwargs and then setting on a per-version level
+ match the upstream interface to avoid mypy linting warning. + pydantic added exclude_computed_fields in pydantic/pydantic-core#1780
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks so much @spazm !
It looks like your PR addresses 3 issues, 2 of which are specifically caused by mypy
errors on the latest Pydantic release. These 2 are urgent to fix, and I would like to split them into a separate PR so it's easier to review and merge.
The other fix you mentioned about handling model_dump
will definitely be looked at as well, but let's focus on getting the CI running first.
Please let me know if you have time to split this into a separate PR right now, otherwise I can do it.
Or @YuriiMotov: I would go ahead and reopen #1591 to handle the |
I think we should go with this PR. In my PR I didn't handle older Pydantic versions properly, so it would fail. |
Ok, if you feel that we should merge this as one atomic PR that's fine as well, then let's get it ready for Tiangolo to merge so we can fix the CI ASAP 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
model_dump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! 🙌
And thanks @svlandeg and @YuriiMotov for the help 🚀
model_dump
model_dump
for compatibility with the latest Pydantic versions
else
block added to fix linting errors (4b5ad42) for 💚 Fix linting in CI #1340 was obliterating the'context'
and'serialize_as_any'
attributes for versions >= 2.7 and < 2.11.extra_kwargs
and then setting on a per-version level@final
FieldInfoexclude_computed_fields
from pydantic 2.12exclude_computed_fields
serialization option pydantic/pydantic-core#1780