From aa3325bb54df9a653f083de335c33669021d43b7 Mon Sep 17 00:00:00 2001 From: honglei Date: Fri, 25 Aug 2023 21:30:10 +0800 Subject: [PATCH] ugly way to fix py3.8/Annotation --- sqlmodel/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sqlmodel/main.py b/sqlmodel/main.py index 7d94c40..cc5e8d9 100644 --- a/sqlmodel/main.py +++ b/sqlmodel/main.py @@ -448,7 +448,7 @@ def _is_optional_or_union(type_: Optional[type]) -> bool: def get_sqlalchemy_type(field: FieldInfo) -> Any: - type_: Optional[type] = field.annotation + type_: Optional[type] | _AnnotatedAlias = field.annotation # Resolve Optional/Union fields @@ -473,7 +473,7 @@ def get_sqlalchemy_type(field: FieldInfo) -> Any: if type2 is pydantic.AnyUrl: meta = get_args(type_)[1] return AutoString(length=meta.max_length) - elif org_type is pydantic.AnyUrl: + elif org_type is pydantic.AnyUrl and type(type_) is _AnnotatedAlias: return AutoString(type_.__metadata__[0].max_length) # The 3rd is PydanticGeneralMetadata