From 4b17d0306421cab9821125fb774d1ff89b36e77e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 10 Jan 2020 10:30:13 -0500 Subject: 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 --- lib/sqlalchemy/sql/elements.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/sqlalchemy/sql') 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, -- cgit v1.2.1