]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- reopened #2453, needed to put in the original patch as well to cover the case
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Apr 2012 13:59:22 +0000 (09:59 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 3 Apr 2012 13:59:22 +0000 (09:59 -0400)
of column_property() objs building off each other

lib/sqlalchemy/sql/expression.py
test/sql/test_selectable.py

index f37faa801f6a75d0404706242ba26808d0c183e9..f9a3863da8145fc50503a40113dde26831c6b627 100644 (file)
@@ -4802,6 +4802,15 @@ class Select(_SelectBase):
 
         toremove = set(itertools.chain(*[f._hide_froms for f in froms]))
         if toremove:
+            # if we're maintaining clones of froms,
+            # add the copies out to the toremove list
+            if self._from_cloned:
+                toremove.update(
+                    self._from_cloned[f] for f in 
+                    toremove.intersection(self._from_cloned)
+                )
+            # filter out to FROM clauses not in the list,
+            # using a list to maintain ordering
             froms = [f for f in froms if f not in toremove]
 
         if len(froms) > 1 or self._correlate:
index 7befa8283f976becf1024e2f02303587fa169557..bbb9131a5225710c7967638928685bbfeafca972 100644 (file)
@@ -1136,9 +1136,12 @@ class AnnotationsTest(fixtures.TestBase):
 
     def test_annotate_unique_traversal(self):
         """test that items are copied only once during
-        annotate, deannotate traversal"""
+        annotate, deannotate traversal
+
+        #2453
+        """
         table1 = table('table1', column('x'))
-        table2 = table('table1', column('y'))
+        table2 = table('table2', column('y'))
         a1 = table1.alias()
         s = select([a1.c.x]).select_from(
                 a1.join(table2, a1.c.x==table2.c.y)
@@ -1158,6 +1161,33 @@ class AnnotationsTest(fixtures.TestBase):
             assert sel._froms[0] is sel._froms[1].left
             eq_(str(s), str(sel))
 
+    def test_annotate_fromlist_preservation(self):
+        """test the FROM list in select still works
+        even when multiple annotate runs have created
+        copies of the same selectable
+
+        #2453, continued
+
+        """
+        table1 = table('table1', column('x'))
+        table2 = table('table2', column('y'))
+        a1 = table1.alias()
+        s = select([a1.c.x]).select_from(
+                a1.join(table2, a1.c.x==table2.c.y)
+            )
+
+        assert_s = select([select([s])])
+        for fn in (
+            sql_util._deep_deannotate,
+            lambda s: sql_util._deep_annotate(s, {'foo':'bar'}),
+            lambda s:visitors.cloned_traverse(s, {}, {}),
+            lambda s:visitors.replacement_traverse(s, {}, lambda x:None)
+        ):
+
+            sel = fn(select([fn(select([fn(s)]))]))
+            eq_(str(assert_s), str(sel))
+
+
     def test_bind_unique_test(self):
         t1 = table('t', column('a'), column('b'))