From: Mike Bayer Date: Fri, 10 Feb 2012 22:59:06 +0000 (-0500) Subject: tweak for correlated subqueries here, seems to work for test_eager_relations:Correlat... X-Git-Tag: rel_0_8_0b1~477^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d693180be8c7f9db79831351751a15d786b86a7;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git tweak for correlated subqueries here, seems to work for test_eager_relations:CorrelatedSubqueryTest but need some more testing here --- diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 9a45a57775..511a5b0c2e 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -100,7 +100,12 @@ def visit_binary_product(fn, expr): """ stack = [] def visit(element): - if element.__visit_name__ == 'binary' and \ + if isinstance(element, (expression.FromClause, + expression._ScalarSelect)): + # we dont want to dig into correlated subqueries, + # those are just column elements by themselves + yield element + elif element.__visit_name__ == 'binary' and \ operators.is_comparison(element.operator): stack.insert(0, element) for l in visit(element.left): diff --git a/test/sql/test_generative.py b/test/sql/test_generative.py index d4f324dd7e..c2e437e878 100644 --- a/test/sql/test_generative.py +++ b/test/sql/test_generative.py @@ -250,6 +250,18 @@ class BinaryEndpointTraversalTest(fixtures.TestBase): ] ) + def test_subquery(self): + a, b, c = column("a"), column("b"), column("c") + subq = select([c]).where(c == a).as_scalar() + expr = and_(a == b, b == subq) + self._assert_traversal( + expr, + [ + (operators.eq, a, b), + (operators.eq, b, subq), + ] + ) + class ClauseTest(fixtures.TestBase, AssertsCompiledSQL): """test copy-in-place behavior of various ClauseElements."""