From b0c95e813f7cd603a84b055ec7715e0aa6ff5d4b Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 13 Jan 2025 14:02:37 +0100 Subject: [PATCH] fix too strict skip_registry --- edgy/core/db/models/metaclasses.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/edgy/core/db/models/metaclasses.py b/edgy/core/db/models/metaclasses.py index eadb102f..1a187336 100644 --- a/edgy/core/db/models/metaclasses.py +++ b/edgy/core/db/models/metaclasses.py @@ -784,16 +784,13 @@ def __new__( tablename = f"{name.lower()}s" meta.tablename = tablename meta.model = new_class - if skip_registry: - # don't add automatically to registry. Useful for subclasses which modify the registry itself. - new_class.model_rebuild(force=True) - return new_class - - # Now set the registry of models + # Now find a registry and add it to the meta. This isn't affected by skip_registry. + # Use Meta: registry = False for disabling the search. if meta.registry is None: registry: Union[Registry, None, Literal[False]] = get_model_registry(bases, meta_class) meta.registry = registry or None - if not meta.registry: + # don't add automatically to registry. Useful for subclasses which modify the registry itself. + if not meta.registry or skip_registry: new_class.model_rebuild(force=True) return new_class new_class.add_to_registry(meta.registry, database=database, on_conflict=on_conflict) @@ -839,7 +836,7 @@ def table(cls) -> sqlalchemy.Table: if not cls.meta.registry: # we cannot set the table without a registry # raising is required - raise AttributeError() + raise AttributeError("No registry.") table = getattr(cls, "_table", None) # assert table.name.lower() == cls.meta.tablename, f"{table.name.lower()} != {cls.meta.tablename}" # fix assigned table