]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
read from cls.__dict__ so init_subclass works
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 4 Apr 2022 23:01:54 +0000 (19:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 13 Apr 2022 13:06:24 +0000 (09:06 -0400)
commit289894f9af4bebee499969ee8701e06eb8527913
treef7433454ef208024af9d7984a5aaa1f91e8c3098
parent2d7d343823f06dd31503368b4f7ad060e802d0bb
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
(cherry picked from commit 428ea01f00a9cc7f85e435018565eb6da7af1b77)
doc/build/changelog/unreleased_14/7900.rst [new file with mode: 0644]
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/decl_base.py
lib/sqlalchemy/orm/instrumentation.py
test/orm/declarative/test_mixin.py