From f7cc199d37e1a428b0d62b545b73c7d6d2c898dc Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Thu, 15 May 2008 16:20:50 +0000 Subject: [PATCH] Don't blat Table.quote= when resolving foreign keys. --- lib/sqlalchemy/schema.py | 18 ++++++++++++------ test/sql/quote.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index a632a19c96..1611697f42 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -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) diff --git a/test/sql/quote.py b/test/sql/quote.py index 7003ce8342..6f474ba609 100644 --- a/test/sql/quote.py +++ b/test/sql/quote.py @@ -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): -- 2.47.3