[Sqlalchemy-commits] sqlalchemy: - reopened #2453, needed to put in the original patc...
Brought to you by:
zzzeek
From: <co...@sq...> - 2012-04-03 13:59:53
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/e49563072578 changeset: 8178:e49563072578 user: Mike Bayer <mi...@zz...> date: Tue Apr 03 09:59:22 2012 -0400 description: - reopened #2453, needed to put in the original patch as well to cover the case of column_property() objs building off each other diffstat: lib/sqlalchemy/sql/expression.py | 9 +++++++++ test/sql/test_selectable.py | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diffs (71 lines): diff -r 641ebde37f98 -r e49563072578 lib/sqlalchemy/sql/expression.py --- a/lib/sqlalchemy/sql/expression.py Sun Apr 01 19:42:54 2012 -0400 +++ b/lib/sqlalchemy/sql/expression.py Tue Apr 03 09:59:22 2012 -0400 @@ -4802,6 +4802,15 @@ 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 -r 641ebde37f98 -r e49563072578 test/sql/test_selectable.py --- a/test/sql/test_selectable.py Sun Apr 01 19:42:54 2012 -0400 +++ b/test/sql/test_selectable.py Tue Apr 03 09:59:22 2012 -0400 @@ -1136,9 +1136,12 @@ 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 @@ 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')) |