FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

🐛 Fix support for `Annotated` fields with Pydantic 2.12+ by stickm4n · Pull Request #1603 · fastapi/sqlmodel · GitHub

Repository navigation

🐛 Fix support for Annotated fields with Pydantic 2.12+ - #1603

Closed
stickm4n wants to merge 24 commits into
fastapi:mainfrom
stickm4n:pydantic-2.12-integration
Closed

stickm4n wants to merge 24 commits into
fastapi:mainfrom
stickm4n:pydantic-2.12-integration

Conversation

Copy link
Copy Markdown
Contributor

After pydantic update to support Python 3.14, different declaration syntax were affected by the changed.
I check and on pydantic side there is not changes on the resulting FieldInfo structure, at least at first glance.
In the tests I illustrated the 3 possible declaration syntax for annotations defined by pydantic and supported so far by sqlmodel. Two of them do not work any more with pydantic>=2.12!

This comment has been minimized.

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

solves #1602

YuriiMotov changed the title Pydantic 2.12 declaration syntax broken 🐛 Fix support for Annotated fields with Pydantic 2.12+ Oct 20, 2025
YuriiMotov added the bug Something isn't working label Oct 20, 2025
Comment thread sqlmodel/main.py Outdated
stickm4n force-pushed the pydantic-2.12-integration branch from 3f6bec5 to eb3cfcc Compare October 20, 2025 20:48

wguilen commented Oct 22, 2025

Copy link
Copy Markdown

Any idea on when a new release with this fix will be available?

Copy link
Copy Markdown
Contributor Author

Any idea on when a new release with this fix will be available?

Not really, hopefully soon!
I would still recommend to use pydantic<2.12 if python 3.14 is not required... there have been big changes recently that could have included some malfunctions like this

wguilen commented Oct 22, 2025

Copy link
Copy Markdown

Any idea on when a new release with this fix will be available?

Not really, hopefully soon! I would still recommend to use pydantic<2.12 if python 3.14 is not required... there have been big changes recently that could have included some malfunctions like this

That's alright, I'll follow your suggestion. Thanks for the quick reply!

svlandeg self-assigned this Oct 30, 2025
svlandeg changed the title 🐛 Fix support for Annotated fields with Pydantic 2.12+ 🐛 Fix support for Annotated fields with Pydantic 2.12+ (alternative 1) Oct 30, 2025
svlandeg linked an issue Oct 30, 2025 that may be closed by this pull request
8 tasks done

svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi @stickm4n, thanks for the PR! I'm going to push some changes to your branch directly, to include also the tests from #1602 and to get the PR in a good state to merge. I'll put it in draft while I work on it.

Copy link
Copy Markdown
Contributor Author

Hi @stickm4n, thanks for the PR! I'm going to push some changes to your branch directly, to include also the tests from #1602 and to get the PR in a good state to merge. I'll put it in draft while I work on it.

Perfect, feel free to do it!
It will be nice for this to me merged soon.

svlandeg marked this pull request as draft October 30, 2025 20:57
svlandeg marked this pull request as ready for review October 30, 2025 21:33
svlandeg changed the title 🐛 Fix support for Annotated fields with Pydantic 2.12+ (alternative 1) 🐛 Fix support for Annotated fields with Pydantic 2.12+ Oct 30, 2025

svlandeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the work on this, @stickm4n!

This now looks good to merge to me. I've added in the tests from #1602 just for good measure, and refactored the code a bit using Yurii's suggestions. I think it's much easier to follow/maintain like this, without the continue & break statements.

Will yet run this by Tiangolo for a final review.
Note that another alternative to this PR is #1607 - if we decide to merge this, we can close the other one.

svlandeg removed their assignment Oct 30, 2025

KSmanis commented Nov 15, 2025

Copy link
Copy Markdown

FYI PR #1607 works with __future__.annotations as well, whereas this one does not.

Copy link
Copy Markdown
Contributor Author

FYI PR #1607 works with __future__.annotations as well, whereas this one does not.

Can you provide more details on this?

KSmanis commented Nov 15, 2025

Copy link
Copy Markdown

Sure, I tested the following model with both PRs, with and without future annotations in Python 3.13:

class CreateTimeMixin:
    create_time: Annotated[AwareDatetime, Field(sa_type=DATETIME_TIMEZONE)]

This PR failed to pick up on the annotated metadata when future annotations were enabled.

sr-verde commented Jan 8, 2026

Copy link
Copy Markdown

@svlandeg, @tiangolo: Is there any chance we get this or #1607 merged soon?

Copy link
Copy Markdown

merge it soon may be helpful for pydantic 2.12+

tiangolo commented Feb 1, 2026

Copy link
Copy Markdown
Member

Thank you @stickm4n! And thanks everyone for the discussion here.

I went with #1607 because that approach, moving the metadata to its own annotation will allow us (in the future) to stop sub-classing FieldInfo, which the Pydantic team have asked for.

I also added a test with stringified annotations (from __future__ import annotations) and that PR fixes/passes that test. ✔️

The fix will be available in the next few hours in SQLModel 0.0.32 🚀

Given that, I'll now close this one. Thanks! ☕

tiangolo closed this Feb 1, 2026
stickm4n deleted the pydantic-2.12-integration branch February 1, 2026 18:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

SQLModel fails to create DB constraints when using Annotated types after Pydantic 2.12.0

9 participants


Back | FazBrowse Home | New Git URL