summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/elements.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-01-10 10:30:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-01-10 11:23:21 -0500
commit4b17d0306421cab9821125fb774d1ff89b36e77e (patch)
treeb6ff077787b030b86a4192da9185bf59ca5e7a8b /lib/sqlalchemy/sql/elements.py
parent2734439fff953a7bb8aecdedb5f851441b5122e9 (diff)
downloadsqlalchemy-4b17d0306421cab9821125fb774d1ff89b36e77e.tar.gz
Alter unique bound parameter key on deserialize
Fixed bug in sqlalchemy.ext.serializer where a unique :class:`.BindParameter` object could conflict with itself if it were present in the mapping itself, as well as the filter condition of the query, as one side would be used against the non-deserialized version and the other side would use the deserialized version. Logic is added to :class:`.BindParameter` similar to its "clone" method which will uniquify the parameter name upon deserialize so that it doesn't conflict with its original. Fixes: #5086 Change-Id: Ie1edce137e92ac496c822831d038999be5d1fc2d
Diffstat (limited to 'lib/sqlalchemy/sql/elements.py')
-rw-r--r--lib/sqlalchemy/sql/elements.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 422eb6220..648394ed2 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -1386,6 +1386,13 @@ class BindParameter(roles.InElementRole, ColumnElement):
d["value"] = v
return d
+ def __setstate__(self, state):
+ if state.get("unique", False):
+ state["key"] = _anonymous_label(
+ "%%(%d %s)s" % (id(self), state.get("_orig_key", "param"))
+ )
+ self.__dict__.update(state)
+
def __repr__(self):
return "BindParameter(%r, %r, type_=%r)" % (
self.key,