Skip to content

Commit

Permalink
fix too strict skip_registry
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Jan 13, 2025
1 parent 9800a15 commit b0c95e8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions edgy/core/db/models/metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b0c95e8

Please sign in to comment.