]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
turn off eager configure_mappers() outside of Query, Load
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 Mar 2021 21:59:44 +0000 (17:59 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 Mar 2021 21:59:44 +0000 (17:59 -0400)
commit547ac69d9dab78af9a7ccd71ee55102f344065f1
tree6283e06cba3d88142a13b12cd72d0bb32e30e0e1
parent4a827330616a90b1fa0a10f86d8e7cb6e92047ba
turn off eager configure_mappers() outside of Query, Load

Fixed regression where producing a Core expression construct such as
:func:`_sql.select` using ORM entities would eagerly configure the mappers,
in an effort to maintain compatibility with the :class:`_orm.Query` object
which necessarily does this to support many backref-related legacy cases.
However, core :func:`_sql.select` constructs are also used in mapper
configurations and such, and to that degree this eager configuration is
more of an inconvenience, so eager configure has been disabled for the
:func:`_sql.select` and other Core constructs in the absence of ORM loading
types of functions such as :class:`_orm.Load`.

The change maintains the behavior of :class:`_orm.Query` so that backwards
compatibility is maintained. However, when using a :func:`_sql.select` in
conjunction with ORM entities, a "backref" that isn't explicitly placed on
one of the classes until mapper configure time won't be available unless
:func:`_orm.configure_mappers` or the newer :func:`_orm.registry.configure`
has been called elsewhere. Prefer using
:paramref:`_orm.relationship.back_populates` for more explicit relationship
configuration which does not have the eager configure requirement.

Fixes: #6066
Change-Id: I7a953ddcc189471fbac63c97c51ab8956f64012e
doc/build/changelog/unreleased_14/6066.rst [new file with mode: 0644]
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/strategy_options.py
lib/sqlalchemy/sql/coercions.py
test/orm/test_events.py
test/orm/test_mapper.py