Skip to content

Commit 1c5263e

Browse files
committed
Support sqlmodel_rebuild, similar to pydantic
1 parent 7d00768 commit 1c5263e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

sqlmodel/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,17 @@ def get_config(name: str) -> Any:
585585
setattr(new_cls, "__abstract__", True) # noqa: B010
586586
return new_cls
587587

588-
# Override SQLAlchemy, allow both SQLAlchemy and plain Pydantic models
589588
def __init__(
590589
cls, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any
590+
) -> None:
591+
return cls.__do_init__(bases, dict_, kw)
592+
593+
def sqlmodel_rebuild(cls) -> None:
594+
return cls.__do_init__(cls.__bases__, cls.__dict__, {})
595+
596+
# Override SQLAlchemy, allow both SQLAlchemy and plain Pydantic models
597+
def __do_init__(
598+
cls, classname: str, bases: Tuple[type, ...], dict_: Dict[str, Any], **kw: Any
591599
) -> None:
592600
# Only one of the base classes (or the current one) should be a table model
593601
# this allows FastAPI cloning a SQLModel for the response_model without

0 commit comments

Comments
 (0)