]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Don't blat Table.quote= when resolving foreign keys.
authorJason Kirtland <jek@discorporate.us>
Thu, 15 May 2008 16:20:50 +0000 (16:20 +0000)
committerJason Kirtland <jek@discorporate.us>
Thu, 15 May 2008 16:20:50 +0000 (16:20 +0000)
lib/sqlalchemy/schema.py
test/sql/quote.py

index a632a19c96d7f098181f66328a7ab49388aedf6c..1611697f42cf3812b46ad10d02904d733e5d6229 100644 (file)
@@ -219,6 +219,11 @@ class Table(SchemaItem, expression.TableClause):
 
         self._set_parent(metadata)
 
+        self.quote = kwargs.pop('quote', None)
+        self.quote_schema = kwargs.pop('quote_schema', None)
+        if kwargs.get('info'):
+            self._info = kwargs.pop('info')
+
         self.__extra_kwargs(**kwargs)
 
         # load column definitions from the database if 'autoload' is defined
@@ -249,6 +254,13 @@ class Table(SchemaItem, expression.TableClause):
                 if c.name not in include_columns:
                     self.c.remove(c)
 
+        for key in ('quote', 'quote_schema'):
+            if key in kwargs:
+                setattr(self, key, kwargs.pop(key))
+
+        if 'info' in kwargs:
+            self._info = kwargs.pop('info')
+
         self.__extra_kwargs(**kwargs)
         self.__post_init(*args, **kwargs)
 
@@ -263,17 +275,11 @@ class Table(SchemaItem, expression.TableClause):
             ['autoload', 'autoload_with', 'schema', 'owner']))
 
     def __extra_kwargs(self, **kwargs):
-        self.quote = kwargs.pop('quote', None)
-        self.quote_schema = kwargs.pop('quote_schema', None)
-        if kwargs.get('info'):
-            self._info = kwargs.pop('info')
-
         # validate remaining kwargs that they all specify DB prefixes
         if len([k for k in kwargs if not re.match(r'^(?:%s)_' % '|'.join(databases.__all__), k)]):
             raise TypeError("Invalid argument(s) for Table: %s" % repr(kwargs.keys()))
         self.kwargs.update(kwargs)
 
-
     def __post_init(self, *args, **kwargs):
         self._init_items(*args)
 
index 7003ce8342a7e2a48b4eac0c64596eedf8ddb399..6f474ba609c33a786b1412b7bb149440d2139e74 100644 (file)
@@ -85,6 +85,21 @@ class QuoteTest(TestBase, AssertsCompiledSQL):
             Column('ColumnOne', Integer, quote=False), quote=False, schema="FooBar", quote_schema=False)
         self.assert_compile(t1.select(), '''SELECT FooBar.TableOne.ColumnOne FROM FooBar.TableOne''')
 
+    def test_table_quote_flag(self):
+        metadata = MetaData()
+        t1 = Table('TableOne', metadata,
+                   Column('id', Integer),
+                   quote=False)
+        t2 = Table('TableTwo', metadata,
+                   Column('id', Integer),
+                   Column('t1_id', Integer, ForeignKey('TableOne.id')),
+                   quote=False)
+
+        self.assert_compile(
+            t2.join(t1).select(),
+            "SELECT TableTwo.id, TableTwo.t1_id, TableOne.id "
+            "FROM TableTwo JOIN TableOne ON TableOne.id = TableTwo.t1_id")
+
     @testing.crashes('oracle', 'FIXME: unknown, verify not fails_on')
     @testing.requires.subqueries
     def testlabels(self):