diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-28 12:14:33 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-28 14:17:54 -0400 |
commit | 3dcdc304a6e40052bc751488187c7e3b515d5be8 (patch) | |
tree | b686f478b484615a0449838ce717800f526d50ed /lib/sqlalchemy/sql/compiler.py | |
parent | 2af1b107fce34b15898e6f534097ad34cfd7d503 (diff) | |
download | sqlalchemy-3dcdc304a6e40052bc751488187c7e3b515d5be8.tar.gz |
accommodate for mutiple copies of bind in ckbm
Fixed critical regression where bound parameter tracking as used in the SQL
caching system could fail to track all parameters for the case where the
same SQL expression containing a parameter were used in an ORM-related
query using a feature such as class inheritance, which was then embedded in
an enclosing expression which would make use of that same expression
multiple times, such as a UNION. The ORM would individually copy the
individual SELECT statements as part of compilation with class inheritance,
which then embedded in the enclosing statement would fail to accommodate
for all parameters. The logic that tracks this condition has been adjusted
to work for multiple copies of a parameter.
Fixes: #6391
Change-Id: I6db5dee0d361a3bb58d753a2d27ef2eee2b369c5
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 6168248ff..dfdf5832f 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -715,7 +715,7 @@ class SQLCompiler(Compiled): self._cache_key_bind_match = ckbm = { b.key: b for b in cache_key[1] } - ckbm.update({b: b for b in cache_key[1]}) + ckbm.update({b: [b] for b in cache_key[1]}) # compile INSERT/UPDATE defaults/sequences to expect executemany # style execution, which may mean no pre-execute of defaults, @@ -934,8 +934,9 @@ class SQLCompiler(Compiled): ckbm = self._cache_key_bind_match resolved_extracted = { - ckbm[b]: extracted + bind: extracted for b, extracted in zip(orig_extracted, extracted_parameters) + for bind in ckbm[b] } else: resolved_extracted = None @@ -2242,7 +2243,6 @@ class SQLCompiler(Compiled): render_postcompile=False, **kwargs ): - if not skip_bind_expression: impl = bindparam.type.dialect_impl(self.dialect) if impl._has_bind_expression: @@ -2313,7 +2313,7 @@ class SQLCompiler(Compiled): for bp in bindparam._cloned_set: if bp.key in ckbm: cb = ckbm[bp.key] - ckbm[cb] = bindparam + ckbm[cb].append(bindparam) if bindparam.isoutparam: self.has_out_parameters = True |