Skip to content

Commit 32370cb

Browse files
committed
Fix: preserve relationship annotations during class creation
1 parent 71da0f5 commit 32370cb

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

sqlmodel/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def __new__(
563563
**dict_for_pydantic,
564564
"__weakref__": None,
565565
"__sqlmodel_relationships__": relationships,
566-
"__annotations__": pydantic_annotations,
566+
"__annotations__": original_annotations,
567567
}
568568
# Duplicate logic from Pydantic to filter config kwargs because if they are
569569
# passed directly including the registry Pydantic will pass them over to the
@@ -581,6 +581,10 @@ def __new__(
581581
new_cls = cast(
582582
"SQLModel", super().__new__(cls, name, bases, dict_used, **config_kwargs)
583583
)
584+
for k in relationships:
585+
if k in new_cls.model_fields:
586+
del new_cls.model_fields[k]
587+
584588
new_cls.__annotations__ = {
585589
**relationship_annotations,
586590
**pydantic_annotations,

0 commit comments

Comments
 (0)