sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

🐛 Fix support for `Annotated` fields with Pydantic 2.12+

Open stickm4n opened this issue 2 months ago • 10 comments

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!

stickm4n avatar Oct 11 '25 03:10 stickm4n

@YuriiMotov Hi again! Maybe take a look at this, this is also related with Python 3.14 support and pydantic>=2.12 update.

stickm4n avatar Oct 11 '25 03:10 stickm4n

@YuriiMotov can you label this as a bug?

stickm4n avatar Oct 17 '25 14:10 stickm4n

solves #1602

stickm4n avatar Oct 20 '25 05:10 stickm4n

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

wguilen avatar Oct 22 '25 19:10 wguilen

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

stickm4n avatar Oct 22 '25 20:10 stickm4n

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!

wguilen avatar Oct 22 '25 20:10 wguilen

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.

stickm4n avatar Oct 30 '25 20:10 stickm4n

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

KSmanis avatar Nov 15 '25 11:11 KSmanis

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

Can you provide more details on this?

stickm4n avatar Nov 15 '25 11:11 stickm4n

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.

KSmanis avatar Nov 15 '25 11:11 KSmanis