]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
port history meta to 2.0
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 2 Feb 2023 19:38:37 +0000 (14:38 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 6 Feb 2023 16:08:50 +0000 (11:08 -0500)
commit3c6acaba017ef0a0b667864199f103f5eb6f79f9
treec8d1ea054d5db18e0d56e2741aa9c75b651af959
parent2459619e751f39a796bb1dd9fe75947dd0961fee
port history meta to 2.0

first change:

Reworked the :ref:`examples_versioned_history` to work with
version 2.0, while at the same time improving the overall working of
this example to use newer APIs, including a newly added hook
:meth:`_orm.MapperEvents.after_mapper_constructed`.

second change:

Added new event hook :meth:`_orm.MapperEvents.after_mapper_constructed`,
which supplies an event hook to take place right as the
:class:`_orm.Mapper` object has been fully constructed, but before the
:meth:`_orm.registry.configure` call has been called. This allows code that
can create additional mappings and table structures based on the initial
configuration of a :class:`_orm.Mapper`, which also integrates within
Declarative configuration. Previously, when using Declarative, where the
:class:`_orm.Mapper` object is created within the class creation process,
there was no documented means of running code at this point.  The change
is to immediately benefit custom mapping schemes such as that
of the :ref:`examples_versioned_history` example, which generate additional
mappers and tables in response to the creation of mapped classes.

third change:

The infrequently used :attr:`_orm.Mapper.iterate_properties` attribute and
:meth:`_orm.Mapper.get_property` method, which are primarily used
internally, no longer implicitly invoke the :meth:`_orm.registry.configure`
process. Public access to these methods is extremely rare and the only
benefit to having :meth:`_orm.registry.configure` would have been allowing
"backref" properties be present in these collections. In order to support
the new :meth:`_orm.MapperEvents.after_mapper_constructed` event, iteration
and access to the internal :class:`_orm.MapperProperty` objects is now
possible without triggering an implicit configure of the mapper itself.

The more-public facing route to iteration of all mapper attributes, the
:attr:`_orm.Mapper.attrs` collection and similar, will still implicitly
invoke the :meth:`_orm.registry.configure` step thus making backref
attributes available.

In all cases, the :meth:`_orm.registry.configure` is always available to
be called directly.

fourth change:

Fixed obscure ORM inheritance issue caused by :ticket:`8705` where some
scenarios of inheriting mappers that indicated groups of columns from the
local table and the inheriting table together under a
:func:`_orm.column_property` would nonetheless warn that properties of the
same name were being combined implicitly.

Fixes: #9220
Fixes: #9232
Change-Id: Id335b8e8071c8ea509c057c389df9dcd2059437d
14 files changed:
doc/build/changelog/unreleased_20/9220.rst [new file with mode: 0644]
doc/build/changelog/unreleased_20/9232.rst [new file with mode: 0644]
examples/versioned_history/__init__.py
examples/versioned_history/history_meta.py
examples/versioned_history/test_versioning.py
lib/sqlalchemy/orm/events.py
lib/sqlalchemy/orm/mapper.py
test/base/test_examples.py [new file with mode: 0644]
test/ext/declarative/test_inheritance.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_concrete.py
test/orm/test_deprecations.py
test/orm/test_events.py
test/orm/test_mapper.py