Skip to content

Commit

Permalink
合并拉取请求 #162
Browse files Browse the repository at this point in the history
[Bug] Fix: pydantic.errors.PydanticUserError: Field 'id' requires a type annotation
  • Loading branch information
amisadmin authored Mar 31, 2024
2 parents 6592be1 + 22b3308 commit 2428d58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fastapi_amis_admin/crud/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,17 @@ def insfield_to_modelfield(insfield: InstrumentedAttribute) -> Optional[ModelFie
elif expression.default.is_callable:
field_info_kwargs["default_factory"] = expression.default.arg
required = False
if isinstance(expression.type, String):
if isinstance(expression.type, String) and expression.type.length:
field_info_kwargs["max_length"] = expression.type.length
if "default_factory" not in field_info_kwargs:
if "default_factory" not in field_info_kwargs and default:
field_info_kwargs["default"] = default
type_ = expression.type.python_type
if PYDANTIC_V2:
field_info_kwargs["annotation"] = type_
if expression.comment:
field_info_kwargs["title"] = expression.comment
return create_response_field(
name=insfield.key, type_=type_, required=required, field_info=Field(title=expression.comment, **field_info_kwargs)
name=insfield.key, type_=type_, required=required, field_info=FieldInfo(**field_info_kwargs)
)


Expand Down

0 comments on commit 2428d58

Please sign in to comment.