]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixed regression dating back to 0.7.9 whereby the name of a CTE might
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Aug 2013 18:46:04 +0000 (14:46 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 18 Aug 2013 18:46:54 +0000 (14:46 -0400)
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

Conflicts:
doc/build/changelog/changelog_08.rst

doc/build/changelog/changelog_07.rst
lib/sqlalchemy/sql/compiler.py
test/sql/test_cte.py

index f01f42608f5c8eebd0563eecbc551b5736dea5f4..738e8974639d43824548af37e1e687d3dfa3f753 100644 (file)
@@ -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
index 2e6301f159ffc4dfd72c7a82851bcea90543ff26..aed004b5d8d8b1248fb12740902452d0d75b0cb1 100644 (file)
@@ -797,7 +797,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
index 71663ca789be4bfa6c3c3f57fcf1f1e029d2907b..b6d7689a1d6f07fde644b4b2e3b6e37c86056866 100644 (file)
@@ -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'),