]> 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:28:25 +0000 (13:28 -0400)
commitbbb82271d3ff982405a8c475f2e38ddb18339b44
treea083fc9a1145921777b7642913cbd6e3cfd5df36
parenta134ec1760df6295d537ff63df7aee83d957bf6a
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.

Fixes: #8399
Change-Id: Ided8e2123915131e3f11cf6b06d773039e73797a
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/strategies.py
lib/sqlalchemy/orm/strategy_options.py
test/orm/test_relationship_criteria.py