Skip to content

Commit 2428d58

Browse files
authored
合并拉取请求 #162
[Bug] Fix: pydantic.errors.PydanticUserError: Field 'id' requires a type annotation
2 parents 6592be1 + 22b3308 commit 2428d58

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

fastapi_amis_admin/crud/parser.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,17 @@ def insfield_to_modelfield(insfield: InstrumentedAttribute) -> Optional[ModelFie
348348
elif expression.default.is_callable:
349349
field_info_kwargs["default_factory"] = expression.default.arg
350350
required = False
351-
if isinstance(expression.type, String):
351+
if isinstance(expression.type, String) and expression.type.length:
352352
field_info_kwargs["max_length"] = expression.type.length
353-
if "default_factory" not in field_info_kwargs:
353+
if "default_factory" not in field_info_kwargs and default:
354354
field_info_kwargs["default"] = default
355355
type_ = expression.type.python_type
356356
if PYDANTIC_V2:
357357
field_info_kwargs["annotation"] = type_
358+
if expression.comment:
359+
field_info_kwargs["title"] = expression.comment
358360
return create_response_field(
359-
name=insfield.key, type_=type_, required=required, field_info=Field(title=expression.comment, **field_info_kwargs)
361+
name=insfield.key, type_=type_, required=required, field_info=FieldInfo(**field_info_kwargs)
360362
)
361363

362364

0 commit comments

Comments
 (0)