ugly way to fix py3.8/Annotation

This commit is contained in:
honglei 2023-08-25 21:30:10 +08:00
parent e0d32fb27a
commit aa3325bb54

View File

@ -448,7 +448,7 @@ def _is_optional_or_union(type_: Optional[type]) -> bool:
def get_sqlalchemy_type(field: FieldInfo) -> Any: def get_sqlalchemy_type(field: FieldInfo) -> Any:
type_: Optional[type] = field.annotation type_: Optional[type] | _AnnotatedAlias = field.annotation
# Resolve Optional/Union fields # Resolve Optional/Union fields
@ -473,7 +473,7 @@ def get_sqlalchemy_type(field: FieldInfo) -> Any:
if type2 is pydantic.AnyUrl: if type2 is pydantic.AnyUrl:
meta = get_args(type_)[1] meta = get_args(type_)[1]
return AutoString(length=meta.max_length) 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) return AutoString(type_.__metadata__[0].max_length)
# The 3rd is PydanticGeneralMetadata # The 3rd is PydanticGeneralMetadata