diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/schema.py | 7 | ||||
-rw-r--r-- | test/engine/test_metadata.py | 15 |
3 files changed, 23 insertions, 3 deletions
@@ -188,6 +188,10 @@ CHANGES coercing a returned floating point value into a string on its way to Decimal - this allows accuracy to function on SQLite, MySQL. [ticket:1717] + + - the copy() method of Column now copies over uninitialized + "on table attach" events. Helps with the new declarative + "mixin" capability. - engines - Added an optional C extension to speed up the sql layer by diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 08386059d..8ffb68a4e 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -813,7 +813,7 @@ class Column(SchemaItem, expression.ColumnClause): [c.copy(**kw) for c in self.constraints] + \ [c.copy(**kw) for c in self.foreign_keys if not c.constraint] - return Column( + c = Column( name=self.name, type_=self.type, key = self.key, @@ -828,7 +828,10 @@ class Column(SchemaItem, expression.ColumnClause): server_onupdate=self.server_onupdate, *args ) - + if hasattr(self, '_table_events'): + c._table_events = list(self._table_events) + return c + def _make_proxy(self, selectable, name=None): """Create a *proxy* for this column. diff --git a/test/engine/test_metadata.py b/test/engine/test_metadata.py index 0d2cb7775..3a1a19cd4 100644 --- a/test/engine/test_metadata.py +++ b/test/engine/test_metadata.py @@ -54,7 +54,20 @@ class MetaDataTest(TestBase, ComparesTables): for a1, a2 in zip(col.foreign_keys, c2.foreign_keys): assert a1 is not a2 eq_(a2._colspec, 'bat.blah') - + + def test_uninitialized_column_copy_events(self): + msgs = [] + def write(t, c): + msgs.append("attach %s.%s" % (t.name, c.name)) + c1 = Column('foo', String()) + c1._on_table_attach(write) + m = MetaData() + for i in xrange(3): + cx = c1.copy() + t = Table('foo%d' % i, m, cx) + eq_(msgs, ['attach foo0.foo', 'attach foo1.foo', 'attach foo2.foo']) + + def test_dupe_tables(self): metadata = MetaData() t1 = Table('table1', metadata, Column('col1', Integer, primary_key=True), |