From: Mike Bayer Date: Sat, 2 Aug 2014 18:42:57 +0000 (-0400) Subject: - Fixed bug in CTE where ``literal_binds`` compiler argument would not X-Git-Tag: rel_1_0_0b1~257 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7c80e521f00a52254678acb7dab632be3e6d0119;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Fixed bug in CTE where ``literal_binds`` compiler argument would not be always be correctly propagated when one CTE referred to another aliased CTE in a statement. Fixes #3154 --- diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index afc51f2400..cde13441f6 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -13,6 +13,15 @@ .. changelog:: :version: 0.9.8 + .. change:: + :tags: bug, sql + :versions: 1.0.0 + :tickets: 3154 + + Fixed bug in CTE where ``literal_binds`` compiler argument would not + be always be correctly propagated when one CTE referred to another + aliased CTE in a statement. + .. change:: :tags: bug, postgresql :versions: 1.0.0 diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index ac45054aeb..e45510aa4f 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -1120,7 +1120,7 @@ class SQLCompiler(Compiled): if cte._cte_alias is not None: orig_cte = cte._cte_alias if orig_cte not in self.ctes: - self.visit_cte(orig_cte) + self.visit_cte(orig_cte, **kwargs) cte_alias_name = cte._cte_alias.name if isinstance(cte_alias_name, elements._truncated_label): cte_alias_name = self._truncated_identifier( diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index 7e83968da7..b907fe649b 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -391,6 +391,44 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): 'regional_sales_2."order" FROM regional_sales_2', checkpositional=('x', 'y', 'z'), dialect=dialect) + def test_positional_binds_2_asliteral(self): + orders = table('orders', + column('order'), + ) + s = select([orders.c.order, literal("x")]).cte("regional_sales") + s = select([s.c.order, literal("y")]) + dialect = default.DefaultDialect() + dialect.positional = True + dialect.paramstyle = 'numeric' + s1 = select([orders.c.order]).where(orders.c.order == 'x').\ + cte("regional_sales_1") + + s1a = s1.alias() + + s2 = select([orders.c.order == 'y', s1a.c.order, + orders.c.order, s1.c.order]).\ + where(orders.c.order == 'z').\ + cte("regional_sales_2") + + s3 = select([s2]) + + self.assert_compile( + s3, + 'WITH regional_sales_1 AS ' + '(SELECT orders."order" AS "order" ' + 'FROM orders ' + 'WHERE orders."order" = \'x\'), ' + 'regional_sales_2 AS ' + '(SELECT orders."order" = \'y\' AS anon_1, ' + 'anon_2."order" AS "order", orders."order" AS "order", ' + 'regional_sales_1."order" AS "order" ' + 'FROM orders, regional_sales_1 AS anon_2, regional_sales_1 ' + 'WHERE orders."order" = \'z\') ' + 'SELECT regional_sales_2.anon_1, regional_sales_2."order" ' + 'FROM regional_sales_2', + checkpositional=(), dialect=dialect, + literal_binds=True) + def test_all_aliases(self): orders = table('order', column('order')) s = select([orders.c.order]).cte("regional_sales")