From f0aa20cab011488b1cdecb5ed9bc68fc1ef1f73e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 4 Feb 2006 23:41:07 +0000 Subject: [PATCH] columns can be specified to override those from autoload=True --- lib/sqlalchemy/schema.py | 9 +++++---- test/engines.py | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 6679c8b057..a5e6e0777f 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -81,14 +81,16 @@ class TableSingleton(type): except KeyError: if mustexist: raise "Table '%s.%s' not defined" % (schema, name) - table = type.__call__(self, name, engine, *args, **kwargs) + table = type.__call__(self, name, engine, **kwargs) engine.tables[key] = table # load column definitions from the database if 'autoload' is defined # we do it after the table is in the singleton dictionary to support # circular foreign keys if autoload: engine.reflecttable(table) - + # initialize all the column, etc. objects. done after + # reflection to allow user-overrides + table._init_items(*args) return table @@ -98,7 +100,7 @@ class Table(SchemaItem): Be sure to look at sqlalchemy.sql.TableImpl for additional methods defined on a Table.""" __metaclass__ = TableSingleton - def __init__(self, name, engine, *args, **kwargs): + def __init__(self, name, engine, **kwargs): """Table objects can be constructed directly. The init method is actually called via the TableSingleton metaclass. Arguments are: @@ -138,7 +140,6 @@ class Table(SchemaItem): self.primary_key = [] self.engine = engine self._impl = self.engine.tableimpl(self) - self._init_items(*args) self.schema = kwargs.pop('schema', None) if self.schema is not None: self.fullname = "%s.%s" % (self.schema, self.name) diff --git a/test/engines.py b/test/engines.py index 10aa380bac..25bfb3eac0 100644 --- a/test/engines.py +++ b/test/engines.py @@ -117,8 +117,30 @@ class EngineTest(PersistTest): assert not pgtable.c.name.nullable assert pgtable.c.description.nullable + def testoverride(self): + table = Table( + 'override_test', testbase.db, + Column('col1', Integer, primary_key=True), + Column('col2', String(20)), + Column('col3', Numeric) + ) + table.create() + # clear out table registry + table.deregister() + + try: + table = Table( + 'override_test', testbase.db, + Column('col2', Unicode()), + Column('col4', String(30)), autoload=True) - + print repr(table) + self.assert_(isinstance(table.c.col1.type, Integer)) + self.assert_(table.c.col2.type.is_unicode) + self.assert_(isinstance(table.c.col4.type, String)) + finally: + table.drop() + if __name__ == "__main__": testbase.main() -- 2.47.2