From: Mike Bayer Date: Tue, 3 Apr 2012 13:59:22 +0000 (-0400) Subject: - reopened #2453, needed to put in the original patch as well to cover the case X-Git-Tag: rel_0_7_7~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1378bf0d25319f3725cfe8ff947a5f0aeae4cc81;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - reopened #2453, needed to put in the original patch as well to cover the case of column_property() objs building off each other --- diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index f37faa801f..f9a3863da8 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -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: diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 7befa8283f..bbb9131a52 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -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'))