Skip to content

Commit 38dc566

Browse files
committed
Simplify logic
1 parent 93e15c1 commit 38dc566

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sqlmodel/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,14 @@ def get_config(name: str) -> Any:
563563
set_config_value(model=new_cls, parameter="table", value=config_table)
564564
for k, v in get_model_fields(new_cls).items():
565565
original_field = getattr(v, "_original_assignment", Undefined)
566-
annotated_field_meta = new_cls.__annotations__[k].__dict__.get("__metadata__", [])
567-
annotated_field = next((f for f in annotated_field_meta if isinstance(f, FieldInfo)), None)
568-
field = original_field if isinstance(original_field, FieldInfo) else (annotated_field or v)
569566
# Get the original sqlmodel FieldInfo, pydantic >=v2.12 changes the model
570-
field.annotation = v.annotation
571-
# Guarantee the field has the correct type
567+
if isinstance(original_field, FieldInfo):
568+
field = original_field
569+
else:
570+
annotated_field_meta = new_cls.__annotations__[k].__dict__.get("__metadata__", [])
571+
field = next((f for f in annotated_field_meta if isinstance(f, FieldInfo)), v)
572+
field.annotation = v.annotation
573+
# Guarantee the field has the correct type
572574
col = get_column_from_field(field)
573575
setattr(new_cls, k, col)
574576
# Set a config flag to tell FastAPI that this should be read with a field

0 commit comments

Comments
 (0)