diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-07-24 17:51:01 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-07-24 17:51:01 -0400 |
| commit | 8a483dbf38168ff43ca0652229b1d46afb23235d (patch) | |
| tree | 0707d1e1f3912bda8262e32bd1e4e008a7c67b88 /test/sql | |
| parent | 9867086943d60e347695930dd7f442f9e95e4577 (diff) | |
| download | sqlalchemy-8a483dbf38168ff43ca0652229b1d46afb23235d.tar.gz | |
- rewrite cloned_traverse() and replacement_traverse() to use a straight
recursive descent with clone() + _copy_internals(). This is essentially
what it was doing anyway with lots of unnecessary steps.
Fix Alias() to honor the given clone() function which may have been the
reason the traversal hadn't been fixed sooner. Alias._copy_internals()
will specifically skip an alias of a Table
as a more specific form of what it was doing before. This may need to
be further improved such that ClauseAdapter or replacement_traverse()
send it some specific hints what not to dig into; **kw has been added
to all _copy_internals() to support this. replacement/clone traversal
is at least clear now.
- apply new no_replacement_traverse annotation to join created by
_create_joins(), fixes [ticket:2195]
- can replace orm.query "_halt_adapt" with "no_replacement_traverse"
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_generative.py | 13 | ||||
| -rw-r--r-- | test/sql/test_selectable.py | 7 |
2 files changed, 19 insertions, 1 deletions
diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index 47e45bbb9..f9333dbf5 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -779,7 +779,7 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): s2 = s2._clone() assert s2.is_derived_from(s1) - def test_aliasedselect_to_aliasedselect(self): + def test_aliasedselect_to_aliasedselect_straight(self): # original issue from ticket #904 @@ -791,6 +791,10 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): 'AS col2, table1.col3 AS col3 FROM table1) ' 'AS foo LIMIT :param_1 OFFSET :param_2', {'param_1': 5, 'param_2': 10}) + + def test_aliasedselect_to_aliasedselect_join(self): + s1 = select([t1]).alias('foo') + s2 = select([s1]).limit(5).offset(10).alias() j = s1.outerjoin(t2, s1.c.col1 == t2.c.col1) self.assert_compile(sql_util.ClauseAdapter(s2).traverse(j).select(), 'SELECT anon_1.col1, anon_1.col2, ' @@ -803,8 +807,15 @@ class ClauseAdapterTest(fixtures.TestBase, AssertsCompiledSQL): ':param_2) AS anon_1 LEFT OUTER JOIN ' 'table2 ON anon_1.col1 = table2.col1', {'param_1': 5, 'param_2': 10}) + + def test_aliasedselect_to_aliasedselect_join_nested_table(self): + s1 = select([t1]).alias('foo') + s2 = select([s1]).limit(5).offset(10).alias() talias = t1.alias('bar') + + assert not s2.is_derived_from(talias) j = s1.outerjoin(talias, s1.c.col1 == talias.c.col1) + self.assert_compile(sql_util.ClauseAdapter(s2).traverse(j).select(), 'SELECT anon_1.col1, anon_1.col2, ' 'anon_1.col3, bar.col1, bar.col2, bar.col3 ' diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py index 63be50a97..555271f16 100644 --- a/test/sql/test_selectable.py +++ b/test/sql/test_selectable.py @@ -914,6 +914,13 @@ class AnnotationsTest(fixtures.TestBase): b5 = visitors.cloned_traverse(b3, {}, {'binary':visit_binary}) assert str(b5) == ":bar = table1.col2" + def test_annotate_aliased(self): + t1 = table('t1', column('c1')) + s = select([(t1.c.c1 + 3).label('bat')]) + a = s.alias() + a = sql_util._deep_annotate(a, {'foo': 'bar'}) + eq_(a._annotations['foo'], 'bar') + eq_(a.element._annotations['foo'], 'bar') def test_annotate_expressions(self): table1 = table('table1', column('col1'), column('col2')) |
