From d934ea23e24880a5c784c9e5edf9ead5bc965a83 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 11 Feb 2012 20:33:56 -0500 Subject: - figured out again why deannotate must clone() - got everything working. just need to update error strings --- lib/sqlalchemy/sql/expression.py | 13 +++++++++---- lib/sqlalchemy/sql/util.py | 4 ++-- lib/sqlalchemy/sql/visitors.py | 6 +++--- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index ebf4de9a2..573ace47f 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -1589,7 +1589,7 @@ class ClauseElement(Visitable): """ return sqlutil.Annotated(self, values) - def _deannotate(self, values=None): + def _deannotate(self, values=None, clone=False): """return a copy of this :class:`.ClauseElement` with annotations removed. @@ -1597,9 +1597,14 @@ class ClauseElement(Visitable): to remove. """ - # since we have no annotations we return - # self - return self + if clone: + # clone is used when we are also copying + # the expression for a deep deannotation + return self._clone() + else: + # if no clone, since we have no annotations we return + # self + return self def unique_params(self, *optionaldict, **kwargs): """Return a copy with :func:`bindparam()` elments replaced. diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index e4e2c00e1..2862e9af9 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -424,7 +424,7 @@ class Annotated(object): clone._annotations = values return clone - def _deannotate(self, values=None): + def _deannotate(self, values=None, clone=True): if values is None: return self.__element else: @@ -498,7 +498,7 @@ def _deep_deannotate(element, values=None): """Deep copy the given element, removing annotations.""" def clone(elem): - elem = elem._deannotate(values=values) + elem = elem._deannotate(values=values, clone=True) elem._copy_internals(clone=clone) return elem diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py index 75e099f0d..cd178b716 100644 --- a/lib/sqlalchemy/sql/visitors.py +++ b/lib/sqlalchemy/sql/visitors.py @@ -222,13 +222,13 @@ def cloned_traverse(obj, opts, visitors): if elem in stop_on: return elem else: - if elem not in cloned: - cloned[elem] = newelem = elem._clone() + if id(elem) not in cloned: + cloned[id(elem)] = newelem = elem._clone() newelem._copy_internals(clone=clone) meth = visitors.get(newelem.__visit_name__, None) if meth: meth(newelem) - return cloned[elem] + return cloned[id(elem)] if obj is not None: obj = clone(obj) -- cgit v1.2.1