From a47c158a9a3b1104698fc0bff47ca58d67cb9191 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 30 Apr 2021 11:54:52 -0400 Subject: track_on needs to be a fixed size, support sub-tuples Fixed regression in ``selectinload`` loader strategy that would cause it to cache its internal state incorrectly when handling relationships that join across more than one column, such as when using a composite foreign key. The invalid caching would then cause other loader operations to fail. Fixes: #6410 Change-Id: I9f95ccca3553e7fd5794c619be4cf85c02b04626 --- lib/sqlalchemy/sql/lambdas.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql/lambdas.py') diff --git a/lib/sqlalchemy/sql/lambdas.py b/lib/sqlalchemy/sql/lambdas.py index 06db8f95e..ddc4774db 100644 --- a/lib/sqlalchemy/sql/lambdas.py +++ b/lib/sqlalchemy/sql/lambdas.py @@ -772,7 +772,16 @@ class AnalyzedCode(object): from the "track_on" parameter passed to a :class:`.LambdaElement`. """ - if isinstance(elem, traversals.HasCacheKey): + + if isinstance(elem, tuple): + # tuple must contain hascachekey elements + def get(closure, opts, anon_map, bindparams): + return tuple( + tup_elem._gen_cache_key(anon_map, bindparams) + for tup_elem in opts.track_on[idx] + ) + + elif isinstance(elem, traversals.HasCacheKey): def get(closure, opts, anon_map, bindparams): return opts.track_on[idx]._gen_cache_key(anon_map, bindparams) -- cgit v1.2.1