]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
avoid putting annotated columns in sets
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Nov 2022 18:18:45 +0000 (13:18 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 14 Nov 2022 18:43:02 +0000 (13:43 -0500)
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
lib/sqlalchemy/sql/elements.py
test/sql/test_selectable.py

index ec685d1fac144d9b0c99dfc58229d330434b6e89..4519e649ba650ac9f17e2fcf6df5a0f5ab5bacf2 100644 (file)
@@ -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)
                         ],
                     )
index 72486e749ab558161489a8885e8b8f53b2e0e7c3..d438e5995cd54091b91f18135baa25924e755a54 100644 (file)
@@ -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):
index a3f7b7c468206b5e179f5306c593de8d08d3fd9f..c29d9d5a50a0727c45a1edbbed6b30e2c9695856 100644 (file)
@@ -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})