Skip to content

Commit

Permalink
🐛 Fix set varchar limit when max_length is set on Pydantic models u…
Browse files Browse the repository at this point in the history
…sing Pydantic v2 (#963)

Co-authored-by: Sebastián Ramírez <[email protected]>
  • Loading branch information
estebanx64 and tiangolo authored Jun 4, 2024
1 parent a319952 commit 5bb4cff
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sqlmodel/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def partial_init() -> Generator[None, None, None]:


if IS_PYDANTIC_V2:
from annotated_types import MaxLen
from pydantic import ConfigDict as BaseConfig
from pydantic._internal._fields import PydanticMetadata
from pydantic._internal._model_construction import ModelMetaclass
Expand Down Expand Up @@ -201,7 +202,7 @@ def get_type_from_field(field: Any) -> Any:

def get_field_metadata(field: Any) -> Any:
for meta in field.metadata:
if isinstance(meta, PydanticMetadata):
if isinstance(meta, (PydanticMetadata, MaxLen)):
return meta
return FakeMetadata()

Expand Down

0 comments on commit 5bb4cff

Please sign in to comment.