From 6636cd9d256ccbad651eba6553ec46391380cc93 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 1 Jul 2019 22:33:26 -0400 Subject: Clear proxy_set cache when creating an annotated column Fixed an unlikely issue where the "corresponding column" routine for unions and other :class:`.CompoundSelect` objects could return the wrong column in some overlapping column situtations, thus potentially impacting some ORM operations when set operations are in use, if the underlying :func:`.select` constructs were used previously in other similar kinds of routines, due to a cached value not being cleared. Fixes: #4747 Change-Id: I7fb134cac3604f8fe62e220fb24a0945d0a1c56f --- lib/sqlalchemy/sql/elements.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/sqlalchemy/sql/elements.py') diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index cc57e58e5..aa7b7f688 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -635,6 +635,7 @@ class ColumnElement( __visit_name__ = "column_element" primary_key = False foreign_keys = [] + _proxies = () _label = None """The named label that can be used to target @@ -783,16 +784,13 @@ class ColumnElement( @util.memoized_property def base_columns(self): - return util.column_set( - c for c in self.proxy_set if not hasattr(c, "_proxies") - ) + return util.column_set(c for c in self.proxy_set if not c._proxies) @util.memoized_property def proxy_set(self): s = util.column_set([self]) - if hasattr(self, "_proxies"): - for c in self._proxies: - s.update(c.proxy_set) + for c in self._proxies: + s.update(c.proxy_set) return s def shares_lineage(self, othercolumn): @@ -4388,6 +4386,8 @@ class AnnotatedColumnElement(Annotated): def __init__(self, element, values): Annotated.__init__(self, element, values) ColumnElement.comparator._reset(self) + if self._proxies: + ColumnElement.proxy_set._reset(self) for attr in ("name", "key", "table"): if self.__dict__.get(attr, False) is None: self.__dict__.pop(attr) -- cgit v1.2.1