Skip to content

Commit 80f2935

Browse files
committed
registry: unregister the manager and class
1 parent 1c5263e commit 80f2935

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sqlmodel/main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,14 @@ def __init__(
591591
return cls.__do_init__(bases, dict_, kw)
592592

593593
def sqlmodel_rebuild(cls) -> None:
594+
reg = cls._sa_registry
595+
# clear any exisiting mappers for the cls
596+
manager = [m for m in reg._managers if m.class_ == cls]
597+
if len(manager) > 0:
598+
for m in manager:
599+
reg._dispose_manager_and_mapper(m)
600+
del reg._managers[m]
601+
594602
return cls.__do_init__(cls.__bases__, cls.__dict__, {})
595603

596604
# Override SQLAlchemy, allow both SQLAlchemy and plain Pydantic models

0 commit comments

Comments
 (0)