]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
rewrite _extra_criteria in selectinload; propagate correctly to Load
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Aug 2021 15:07:17 +0000 (11:07 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 17 Aug 2021 19:14:47 +0000 (15:14 -0400)
commita7899c44ba15076df8869f5b40d720ccf09d5273
tree89e06c251a29f03283914e52fe140d5c8cfb111b
parent1b5ae17384660e9153168d1250003b87da690542
rewrite _extra_criteria in selectinload; propagate correctly to Load

Fixed issue in :func:`_orm.selectinload` where use of the new
:meth:`_orm.PropComparator.and_` feature within options that were nested
more than one level deep would fail to update bound parameter values that
were in the nested criteria, as a side effect of SQL statement caching.

Implementation adds a new step that rewrites the parameters
inside of all _extra_criteria when invoking selectinload
as well as subqueryload.  Additionally, changed how Load()
gets "extra_criteria", in that it pulls it from
UnboundLoad._extra_criteria instead of re-fetching it from the
path elements, which are not updated by this new step.

This patch also builds upon the removal of lambda queries
for use in loader strategies in #6889.  lambdas made this issue
much more difficult to diagnose.  An attempt to reintroduce
lambdas here after finally identifying the "extra_criteria"
issue above showed that lambdas still impact the
assertsql fixture, meaning we have a statement structure that
upon calling .compile() still delivers stale data due to lambdas,
even if caching is turned off, and the non-cached test was still
failing due to stale data within the lambdas.

This is basically the complexity that #6889 fixes and as there's
no real performance gain to using lambdas in these strategies
on top of the existing statement caching that does most of the
work, it should be much less likely going forward to have as many
deeply confusing issues as we've had within selectinload/lazyload
in the 1.4 series.

Fixes: #6881
Change-Id: I919c079d2ed06125def5f8d6d81f3f305e158c04
doc/build/changelog/unreleased_14/6881.rst [new file with mode: 0644]
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/orm/strategy_options.py
lib/sqlalchemy/testing/assertsql.py
test/orm/test_eager_relations.py
test/orm/test_relationship_criteria.py