Uh oh!
There was an error while loading. Please reload this page.
SQLModel fails to create DB constraints when using Annotated types after Pydantic 2.12.0 #1597
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example CodeEnvironment:
Pydantic==2.12.0Code:
frompydanticimportStringConstraintsNonEmptyString=Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]
ClassTest(SQLModel):
id: NonEmptyString=Field(primary_key=True) # this was working fine on pydantic v2.11.9DescriptionDescriptionAfter upgrading to Pydantic 2.12.0, Example: fromtypingimportAnnotatedfromsqlmodelimportSQLModel, FieldfrompydanticimportStringConstraintsNonEmptyString=Annotated[str, StringConstraints()]
classTest(SQLModel, table=True):
id: NonEmptyString=Field(primary_key=True)Expected BehaviorThe table should be created with id as an varchar and primary key Actual Behaviorit throws an error Additional notesIn case you use an unique key constraint the table will be created, you will not get any error but the unique key constraint will not be created. Operating SystemLinux Operating System DetailsNo response SQLModel Version0.0.26 Python Version3.13.3 Additional ContextNo response |
Replies: 6 comments 5 replies
Similar: #1596 |
Similar issues for: Pydantic dicriminator: And Python |
Added a fix in this PR: https://github.com/fastapi/sqlmodel/pull/1607/files |
I'm not sure if I should open a new issue for my problem or not, but it's very related to what's being discussed here. This minimal example: fails with I've manually applied the fixes in these PRs (including the one mentioned above), but none of them seem to fix the problem. Are we doing something wrong here? The example here doesn't make much sense, but the original code was one of several experiments with |
There seems to be new additional breakage, but there have been longstanding problems with how sqlmodel deals with annotated types and FieldInfo - e.g. for as long as i've used it, if you have any functional validators in the annotated type, the |
@YuriiMotov@svlandeg Any chance we could convert this to an Issue ? It seems like the latest version of SQLModel broke existing functionality and folks looking for this issue might miss it in Discussion (with an "accepted" answer) |
Added a fix in this PR: https://github.com/fastapi/sqlmodel/pull/1607/files