From bf6adda95461d4c3c2076d39850df2403a157662 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 14 Nov 2022 13:18:45 -0500 Subject: [PATCH] avoid putting annotated columns in sets backporting a small bit of the changes made for the 2.0 version of #8796. See if the changes apply cleanly to the 1.4 branch. Fixes: #8796 Change-Id: I8118511a10beb38c545a55c962a18a77611293af --- lib/sqlalchemy/sql/base.py | 4 ++-- lib/sqlalchemy/sql/elements.py | 8 ++++---- test/sql/test_selectable.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py index ec685d1fac..4519e649ba 100644 --- a/lib/sqlalchemy/sql/base.py +++ b/lib/sqlalchemy/sql/base.py @@ -1430,7 +1430,7 @@ class ColumnCollection(object): operator.add, [ sc._annotations.get("weight", 1) - for sc in col._uncached_proxy_set() + for sc in col._uncached_proxy_list() if sc.shares_lineage(column) ], ) @@ -1438,7 +1438,7 @@ class ColumnCollection(object): operator.add, [ sc._annotations.get("weight", 1) - for sc in c._uncached_proxy_set() + for sc in c._uncached_proxy_list() if sc.shares_lineage(column) ], ) diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 72486e749a..d438e5995c 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -902,21 +902,21 @@ class ColumnElement( @util.memoized_property def proxy_set(self): - s = util.column_set([self]) + s = util.column_set([self._deannotate()]) for c in self._proxies: s.update(c.proxy_set) return s - def _uncached_proxy_set(self): + def _uncached_proxy_list(self): """An 'uncached' version of proxy set. This is so that we can read annotations from the list of columns without breaking the caching of the above proxy_set. """ - s = util.column_set([self]) + s = [self] for c in self._proxies: - s.update(c._uncached_proxy_set()) + s.extend(c._uncached_proxy_list()) return s def shares_lineage(self, othercolumn): diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index a3f7b7c468..c29d9d5a50 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -2975,7 +2975,7 @@ class AnnotationsTest(fixtures.TestBase): # proxy_set, as corresponding_column iterates through proxy_set # in this way d = {} - for col in p2._uncached_proxy_set(): + for col in p2._uncached_proxy_list(): d.update(col._annotations) eq_(d, {"weight": 10}) @@ -2991,7 +2991,7 @@ class AnnotationsTest(fixtures.TestBase): proxy._proxies = [c1._annotate({"weight": 10})] d = {} - for col in proxy._uncached_proxy_set(): + for col in proxy._uncached_proxy_list(): d.update(col._annotations) eq_(d, {"weight": 10}) -- 2.47.2