fix type check for sa_column

This commit is contained in:
honglei 2023-08-15 22:38:03 +08:00
parent f3e7811a80
commit 9e07c1c772
2 changed files with 4 additions and 3 deletions

View File

@ -167,7 +167,7 @@ def Field(
unique: bool = False, unique: bool = False,
nullable: Union[bool, PydanticUndefinedType] = PydanticUndefined, nullable: Union[bool, PydanticUndefinedType] = PydanticUndefined,
index: Union[bool, PydanticUndefinedType] = PydanticUndefined, index: Union[bool, PydanticUndefinedType] = PydanticUndefined,
sa_column: Union[Column, PydanticUndefinedType, types.FunctionType] = PydanticUndefined, # type: ignore sa_column: Union[Column, PydanticUndefinedType, Callable[[], Column]] = PydanticUndefined, # type: ignore
sa_column_args: Union[Sequence[Any], PydanticUndefinedType] = PydanticUndefined, sa_column_args: Union[Sequence[Any], PydanticUndefinedType] = PydanticUndefined,
sa_column_kwargs: Union[ sa_column_kwargs: Union[
Mapping[str, Any], PydanticUndefinedType Mapping[str, Any], PydanticUndefinedType
@ -525,7 +525,9 @@ def get_column_from_field(field: FieldInfo) -> Column: # type: ignore
if isinstance(sa_column, MappedColumn): if isinstance(sa_column, MappedColumn):
return sa_column.column return sa_column.column
if isinstance(sa_column, types.FunctionType): if isinstance(sa_column, types.FunctionType):
return sa_column() col = sa_column()
assert isinstance(col, Column)
return col
sa_type = get_sqlalchemy_type(field) sa_type = get_sqlalchemy_type(field)
primary_key = getattr(field, "primary_key", False) primary_key = getattr(field, "primary_key", False)
index = getattr(field, "index", PydanticUndefined) index = getattr(field, "index", PydanticUndefined)

View File

@ -8,7 +8,6 @@ from sqlalchemy.sql.type_api import TypeEngine
class AutoString(types.TypeDecorator): # type: ignore class AutoString(types.TypeDecorator): # type: ignore
impl = types.String impl = types.String
cache_ok = True cache_ok = True
mysql_default_length = 255 mysql_default_length = 255