From: Mike Bayer Date: Thu, 11 Mar 2010 17:42:06 +0000 (-0500) Subject: - the copy() method of Column now copies over uninitialized X-Git-Tag: rel_0_6beta2~57^2~16^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19de4da70f714a1918ed1370f9a4ac589f20b7de;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - the copy() method of Column now copies over uninitialized "on table attach" events. Helps with the new declarative "mixin" capability. --- diff --git a/CHANGES b/CHANGES index fe9f32396b..00cb3384e3 100644 --- a/CHANGES +++ b/CHANGES @@ -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 08386059de..8ffb68a4eb 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 0d2cb77756..3a1a19cd4a 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),