summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-04-06 09:41:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2022-04-06 10:37:09 -0400
commitd1f97828fd45ad65c46c6cb8eb8e4091ad027274 (patch)
tree489f8aed5ed492c6d5764c7b9aa25aba47262cd1 /lib/sqlalchemy/sql
parent77654cb534de126471263f8876b6be6794da8506 (diff)
downloadsqlalchemy-d1f97828fd45ad65c46c6cb8eb8e4091ad027274.tar.gz
maintain complete cloned_set for BindParameter
Fixed regression caused by :ticket:`7823` which impacted the caching system, such that bound parameters that had been "cloned" within ORM operations, such as polymorphic loading, would in some cases not acquire their correct execution-time value leading to incorrect bind values being rendered. Fixes: #7903 Change-Id: I61c802749b859bebeb127d24e66d6e77d13ce57a (cherry picked from commit 2168a64affb2e299b9a37079af7b2a8d4ae0ff64)
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/elements.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 81645ad0a..da9c5f6b5 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -250,7 +250,6 @@ class ClauseElement(
# old table.
cc = self._is_clone_of
c._is_clone_of = cc if cc is not None else self
-
return c
def _negate_in_binary(self, negated_op, original_op):
@@ -1633,6 +1632,15 @@ class BindParameter(roles.InElementRole, ColumnElement):
def _clone(self, maintain_key=False, **kw):
c = ClauseElement._clone(self, **kw)
+ # ensure all the BindParameter objects stay in cloned set.
+ # in #7823, we changed "clone" so that a clone only keeps a reference
+ # to the "original" element, since for column correspondence, that's
+ # all we need. However, for BindParam, _cloned_set is used by
+ # the "cache key bind match" lookup, which means if any of those
+ # interim BindParameter objects became part of a cache key in the
+ # cache, we need it. So here, make sure all clones keep carrying
+ # forward.
+ c._cloned_set.update(self._cloned_set)
if not maintain_key and self.unique:
c.key = _anonymous_label.safe_construct(
id(c), c._orig_key or "param", sanitize_key=True