]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
refine transfer of cached ORM options for selectin, lazy
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 16 Aug 2022 18:25:12 +0000 (14:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Aug 2022 17:32:06 +0000 (13:32 -0400)
commit0d66f491d0f062bda95e2997d4f70841ac2228d8
tree017d2de03cd5cfd608b5a5cf1e532f463ed7d366
parent0585c66a20b8075252bb4bbdeef0448f224de96a
refine transfer of cached ORM options for selectin, lazy

Fixed issue involving :func:`_orm.with_loader_criteria` where a closure
variable used as bound parameter value within the lambda would not carry
forward correctly into additional relationship loaders such as
:func:`_orm.selectinload` and :func:`_orm.lazyload` after the statement
were cached, using the stale originally-cached value instead.

This change brings forth a good refinement where we finally realize
we shouldn't be testing every ORM option with lots of switches, we
just let the option itself be given "here is your uncached version,
you are cached, tell us what to do!".   the current decision is
that strategy loader options used the cached in all cases as they
always have, with_loader_criteria uses the uncached, because the
uncached will have been invoked with new closure state that we
definitely need.   The only
edge that might not work is if with_loader_criteria referenced
an entity that is local to the query, namely a specific AliasedInsp,
however that's not a documented case for this.  if we had to do that,
then we perhaps would introduce a more complex reconcilation
logic, and this would also give us the hook to do that.

For this approach to work in 1.4, state.load_options has to
be ordered, so, this does the switch of load_options from set->tuple,
which has been in 2.0 for a long time.  if this change is not
feasbile, due to affecting other areas, we may have to scale
back this fix a bit, but for here, it's just two collections
without any deep impacts.

Fixes: #8399
Change-Id: Ided8e2123915131e3f11cf6b06d773039e73797a
(cherry picked from commit 860d582028f6bbbb39cbf17698f7d6b7a8e458ea)
doc/build/changelog/unreleased_14/8399.rst [new file with mode: 0644]
lib/sqlalchemy/orm/context.py
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/orm/strategy_options.py
test/orm/inheritance/test_poly_loading.py
test/orm/test_events.py
test/orm/test_merge.py
test/orm/test_options.py
test/orm/test_relationship_criteria.py