SQLModel fails to create DB constraints when using Annotated types after Pydantic 2.12.0 #1597
-
First Check
Commit to Help
Example CodeEnvironment:
Pydantic==2.12.0
Code:
from pydantic import StringConstraints
NonEmptyString = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]
Class Test(SQLModel):
id: NonEmptyString = Field(primary_key=True) # this was working fine on pydantic v2.11.9DescriptionDescriptionAfter upgrading to Pydantic 2.12.0, Example: from typing import Annotated
from sqlmodel import SQLModel, Field
from pydantic import StringConstraints
NonEmptyString = Annotated[str, StringConstraints()]
class Test(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 |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
|
Similar: #1596 |
Beta Was this translation helpful? Give feedback.
-
|
Similar issues for: Pydantic dicriminator: And Python |
Beta Was this translation helpful? Give feedback.
-
|
Added a fix in this PR: https://github.com/fastapi/sqlmodel/pull/1607/files |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
Added a fix in this PR: https://github.com/fastapi/sqlmodel/pull/1607/files