Skip to content

Commit

Permalink
fix: Fixed the method of determining whether pydantic v2 field is all…
Browse files Browse the repository at this point in the history
…owed to be None
  • Loading branch information
amisadmin committed Dec 22, 2023
1 parent c8cc4ae commit 0fdc9f3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions fastapi_amis_admin/utils/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ def field_outer_type(field: ModelField) -> Any:
return field.field_info.annotation

def field_allow_none(field: ModelField) -> bool:
if is_union(field.field_info.annotation):
for t in get_args(field.field_info.annotation):
if is_none_type(t):
return True
ann = field.field_info.annotation
if not is_union(ann):
origin = get_origin(ann)
if origin is None:
return False
elif origin is Annotated:
return field_allow_none(get_args(ann)[0])
elif not is_union(origin):
return False
for t in get_args(ann):
if is_none_type(t):
return True
return False

@lru_cache(maxsize=512)
Expand Down

0 comments on commit 0fdc9f3

Please sign in to comment.