Skip to content

Conversation

spazm
Copy link
Contributor

@spazm spazm commented Oct 8, 2025

  • ✏️ Fix reversion in model_dump attribute handling for pydantic v2.7 .. v2.10
    • The 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.
    • Fix by initializing extra_kwargs and then setting on a per-version level
  • 💚 Fix linting from overriding @final FieldInfo
  • 💚 Add exclude_computed_fields from pydantic 2.12

spazm added 3 commits October 7, 2025 21:44
…. 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
Copy link
Member

@svlandeg svlandeg left a 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.

@svlandeg svlandeg added the bug Something isn't working label Oct 8, 2025
@svlandeg
Copy link
Member

svlandeg commented Oct 8, 2025

Or @YuriiMotov: I would go ahead and reopen #1591 to handle the mypy errors there separately.

@YuriiMotov
Copy link
Member

Or @YuriiMotov: I would go ahead and reopen #1591 to handle the mypy errors there separately.

I think we should go with this PR. In my PR I didn't handle older Pydantic versions properly, so it would fail.

@svlandeg
Copy link
Member

svlandeg commented Oct 8, 2025

Or @YuriiMotov: I would go ahead and reopen #1591 to handle the mypy errors there separately.

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 🙂

Copy link
Member

@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@svlandeg svlandeg changed the title Fix attribute handling in model_dump 🐛 Fix attribute handling in model_dump Oct 8, 2025
Copy link
Member

@tiangolo tiangolo left a 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 🚀

@tiangolo tiangolo changed the title 🐛 Fix attribute handling in model_dump 🐛 Fix attribute handling in model_dump for compatibility with the latest Pydantic versions Oct 8, 2025
@tiangolo tiangolo merged commit 0402496 into fastapi:main Oct 8, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants