diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-01 22:33:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-07-02 09:57:20 -0400 |
| commit | 6636cd9d256ccbad651eba6553ec46391380cc93 (patch) | |
| tree | 156326031c15adc3f09f885194d230a2039a74a4 /lib/sqlalchemy/sql | |
| parent | 3b60ccaed4844d25617221c853b3e46a78fd7974 (diff) | |
| download | sqlalchemy-6636cd9d256ccbad651eba6553ec46391380cc93.tar.gz | |
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
Diffstat (limited to 'lib/sqlalchemy/sql')
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 12 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/schema.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 1 |
3 files changed, 7 insertions, 8 deletions
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) diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index 62ff25a64..d39bc9832 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -1927,7 +1927,7 @@ class ForeignKey(DialectKWArgs, SchemaItem): parenttable = self.parent.table - # assertion, can be commented out. + # assertion # basically Column._make_proxy() sends the actual # target Column to the ForeignKey object, so the # string resolution here is never called. diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index e38de66e0..2c898e835 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -2759,7 +2759,6 @@ class CompoundSelect(GenerativeSelect): # to how low in the list of select()s the column occurs, so # that the corresponding_column() operation can resolve # conflicts - proxy._proxies = [ c._annotate({"weight": i + 1}) for (i, c) in enumerate(cols) ] |
