From bdfb072f50f773abba2da85e7bf5023b1f9319a4 Mon Sep 17 00:00:00 2001 From: Paul Roever Date: Mon, 25 Mar 2024 23:23:33 +0000 Subject: [PATCH] support field max_length by checking MaxLen type --- sqlmodel/_compat.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sqlmodel/_compat.py b/sqlmodel/_compat.py index 072d2b0f58..f6f083e71c 100644 --- a/sqlmodel/_compat.py +++ b/sqlmodel/_compat.py @@ -18,6 +18,7 @@ Union, ) +from annotated_types import MaxLen from pydantic import VERSION as PYDANTIC_VERSION from pydantic import BaseModel from pydantic.fields import FieldInfo @@ -201,6 +202,10 @@ def get_field_metadata(field: Any) -> Any: for meta in field.metadata: if isinstance(meta, PydanticMetadata): return meta + elif isinstance(meta, MaxLen): + fake = FakeMetadata() + fake.max_length = meta.max_length + return fake return FakeMetadata() def post_init_field_info(field_info: FieldInfo) -> None: