]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix propagation of quote flag within _gen_label() so that if the
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Oct 2013 03:47:49 +0000 (23:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 6 Oct 2013 03:47:49 +0000 (23:47 -0400)
name is already an instance of _anonymous_label(), we don't downgrade
it to a plain quoted_name - fixes regression from [ticket:2812].
[ticket:2834]

lib/sqlalchemy/sql/elements.py
test/sql/test_quote.py

index ea2132e676e5f25f88143af28c756978f2dd7368..73a8a0b82cb1dcc49ce5c4d5d5b2b78f4af7f5d0 100644 (file)
@@ -2018,6 +2018,7 @@ class ColumnClause(Immutable, ColumnElement):
 
     def _gen_label(self, name):
         t = self.table
+
         if self.is_literal:
             return None
 
@@ -2030,8 +2031,14 @@ class ColumnClause(Immutable, ColumnElement):
 
             # propagate name quoting rules for labels.
             if getattr(name, "quote", None) is not None:
-                label = quoted_name(label, name.quote)
+                if isinstance(label, quoted_name):
+                    label.quote = name.quote
+                else:
+                    label = quoted_name(label, name.quote)
             elif getattr(t.name, "quote", None) is not None:
+                # can't get this situation to occur, so let's
+                # assert false on it for now
+                assert not isinstance(label, quoted_name)
                 label = quoted_name(label, t.name.quote)
 
             # ensure the label name doesn't conflict with that
index db1e0b8a5330800cea046d82c3a00e0e2491e5bd..3cab3dc79d5bbaaad3fa4301c4c2464eeb9b5d79 100644 (file)
@@ -612,7 +612,20 @@ class QuoteTest(fixtures.TestBase, AssertsCompiledSQL):
             'CREATE INDEX foo ON t ("x")'
         )
 
+    def test_quote_flag_propagate_anon_label(self):
+        m = MetaData()
+        t = Table('t', m, Column('x', Integer, quote=True))
 
+        self.assert_compile(
+            select([t.alias()]).apply_labels(),
+            'SELECT t_1."x" AS "t_1_x" FROM t AS t_1'
+        )
+
+        t2 = Table('t2', m, Column('x', Integer), quote=True)
+        self.assert_compile(
+            select([t2.c.x]).apply_labels(),
+            'SELECT "t2".x AS "t2_x" FROM "t2"'
+        )
 
 class PreparerTest(fixtures.TestBase):
     """Test the db-agnostic quoting services of IdentifierPreparer."""