diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-06 09:41:11 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-06 10:01:43 -0400 |
commit | 2168a64affb2e299b9a37079af7b2a8d4ae0ff64 (patch) | |
tree | da44a47e6dcd15a0486f39abc580465d5480e2df /lib/sqlalchemy/sql/elements.py | |
parent | 7935b76d9e5b5fd4e64b2c6c3473737186acf2db (diff) | |
download | sqlalchemy-2168a64affb2e299b9a37079af7b2a8d4ae0ff64.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
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r-- | lib/sqlalchemy/sql/elements.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index aec29d1b2..309c01e40 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -370,7 +370,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): @@ -1942,6 +1941,15 @@ class BindParameter(roles.InElementRole, ColumnElement[_T]): self: SelfBindParameter, maintain_key: bool = False, **kw: Any ) -> SelfBindParameter: 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 |