diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-04 19:01:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-12 15:10:32 -0400 |
| commit | 428ea01f00a9cc7f85e435018565eb6da7af1b77 (patch) | |
| tree | 8a39510cc038731e2df8f8b536ae1c533bd23351 /lib/sqlalchemy/orm/instrumentation.py | |
| parent | a45e2284dad17fbbba3bea9d5e5304aab21c8c94 (diff) | |
| download | sqlalchemy-428ea01f00a9cc7f85e435018565eb6da7af1b77.tar.gz | |
read from cls.__dict__ so init_subclass works
Modified the :class:`.DeclarativeMeta` metaclass to pass ``cls.__dict__``
into the declarative scanning process to look for attributes, rather than
the separate dictionary passed to the type's ``__init__()`` method. This
allows user-defined base classes that add attributes within an
``__init_subclass__()`` to work as expected, as ``__init_subclass__()`` can
only affect the ``cls.__dict__`` itself and not the other dictionary. This
is technically a regression from 1.3 where ``__dict__`` was being used.
Additionally makes the reference between ClassManager and
the declarative configuration object a weak reference, so that it
can be discarded after mappers are set up.
Fixes: #7900
Change-Id: I3c2fd4e227cc1891aa4bb3d7d5b43d5686f9f27c
Diffstat (limited to 'lib/sqlalchemy/orm/instrumentation.py')
| -rw-r--r-- | lib/sqlalchemy/orm/instrumentation.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index a5dc305d2..0d4b630da 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -39,6 +39,7 @@ from typing import Optional from typing import Set from typing import TYPE_CHECKING from typing import TypeVar +import weakref from . import base from . import collections @@ -167,7 +168,7 @@ class ClassManager( if registry: registry._add_manager(self) if declarative_scan: - self.declarative_scan = declarative_scan + self.declarative_scan = weakref.ref(declarative_scan) if expired_attribute_loader: self.expired_attribute_loader = expired_attribute_loader |
