]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Use explicit names for mapper _get_clause parameters
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Mar 2021 15:04:58 +0000 (11:04 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Mar 2021 17:56:17 +0000 (13:56 -0400)
commit5f9c45400556f821550e7a39331f1bd5af5a34ce
treef35043d3f4e416eb3734908952da55caefcda994
parentecb392c5f927ab117f9704ce373bf2af1dbe5b69
Use explicit names for mapper _get_clause parameters

Fixed a critical regression in the relationship lazy loader where the SQL
criteria used to fetch a related many-to-one object could go stale in
relation to other memoized structures within the loader if the mapper had
configuration changes, such as can occur when mappers are late configured
or configured on demand, producing a comparison to None and returning no
object. Huge thanks to Alan Hamlett for their help tracking this down late
into the night.

The primary change is that mapper._get_clause() uses a fixed name
for its bound parameters, which is memoized under a lambda statement
in the case of many-to-one lazy loading.  This has implications for some other
logic namely the .compare() used by loader strategies to determine
use_get needed to be adjusted.

This change also repairs the lambda module's behavior of removing
the "required" flag from bound parameters, which caused this issue
to also fail silently rather than issuing an error for a required
bind parameter.

Fixes: #6055
Change-Id: I19e1aba9207a049873e0f13c19bad7541e223cfd
19 files changed:
doc/build/changelog/unreleased_14/6055.rst [new file with mode: 0644]
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/strategies.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/lambdas.py
lib/sqlalchemy/sql/traversals.py
test/ext/test_baked.py
test/orm/inheritance/test_basic.py
test/orm/test_defaults.py
test/orm/test_deferred.py
test/orm/test_dynamic.py
test/orm/test_eager_relations.py
test/orm/test_lazy_relations.py
test/orm/test_merge.py
test/orm/test_unitofworkv2.py
test/orm/test_update_delete.py
test/orm/test_versioning.py
test/sql/test_lambdas.py