From: Mike Bayer Date: Sun, 18 Aug 2013 18:46:04 +0000 (-0400) Subject: Fixed regression dating back to 0.7.9 whereby the name of a CTE might X-Git-Tag: rel_0_8_3~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f0bda7c455a642b505d6133002c4a5fb1e88876;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixed regression dating back to 0.7.9 whereby the name of a CTE might not be properly quoted if it was referred to in multiple FROM clauses. Also in 0.8.3, 0.7.11. [ticket:2801] Conflicts: doc/build/changelog/changelog_09.rst --- diff --git a/doc/build/changelog/changelog_07.rst b/doc/build/changelog/changelog_07.rst index 3504a5134d..c6da742b8d 100644 --- a/doc/build/changelog/changelog_07.rst +++ b/doc/build/changelog/changelog_07.rst @@ -6,6 +6,13 @@ .. changelog:: :version: 0.7.11 + .. change:: + :tags: bug, sql + :tickets: 2801 + + Fixed regression dating back to 0.7.9 whereby the name of a CTE might + not be properly quoted if it was referred to in multiple FROM clauses. + .. change:: :tags: mysql, bug :tickets: 2791 diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 8e4fe4b4ae..bbd2741c80 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -6,6 +6,14 @@ .. changelog:: :version: 0.8.3 + .. change:: + :tags: bug, sql + :tickets: 2801 + + Fixed regression dating back to 0.7.9 whereby the name of a CTE might + not be properly quoted if it was referred to in multiple FROM clauses. + Also in 0.7.11. + .. change:: :tags: bug, examples diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 5f286a3317..01959ee18e 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -913,7 +913,7 @@ class SQLCompiler(engine.Compiled): # we've generated a same-named CTE that we are enclosed in, # or this is the same CTE. just return the name. if cte in existing_cte._restates or cte is existing_cte: - return cte_name + return self.preparer.format_alias(cte, cte_name) elif existing_cte in cte._restates: # we've generated a same-named CTE that is # enclosed in us - we take precedence, so diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py index 5368b9891d..0f68313759 100644 --- a/test/sql/test_cte.py +++ b/test/sql/test_cte.py @@ -312,6 +312,22 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL): "FROM regional_sales" ) + def test_multi_subq_quote(self): + cte = select([literal(1).label("id")]).cte(name='CTE') + + s1 = select([cte.c.id]).alias() + s2 = select([cte.c.id]).alias() + + s = select([s1, s2]) + self.assert_compile( + s, + 'WITH "CTE" AS (SELECT :param_1 AS id) ' + 'SELECT anon_1.id, anon_2.id FROM ' + '(SELECT "CTE".id AS id FROM "CTE") AS anon_1, ' + '(SELECT "CTE".id AS id FROM "CTE") AS anon_2' + ) + + def test_positional_binds(self): orders = table('orders', column('order'),