]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- the copy() method of Column now copies over uninitialized
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Mar 2010 17:42:06 +0000 (12:42 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 11 Mar 2010 17:42:06 +0000 (12:42 -0500)
"on table attach" events.  Helps with the new declarative
"mixin" capability.

CHANGES
lib/sqlalchemy/schema.py
test/engine/test_metadata.py

diff --git a/CHANGES b/CHANGES
index fe9f32396bf1c543c031656957209aac80e8acd6..00cb3384e3df5c8190b39b95fa2978e790c35d5e 100644 (file)
--- 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
index 08386059de343cf712c288a49ea19794ef10c294..8ffb68a4eb7c1ab05ce87118d6eb68acd1ab7d8a 100644 (file)
@@ -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.
 
index 0d2cb7775695c8a0d7b2a3742643670b71c1e42d..3a1a19cd4affdc164094066bacfc54628f886030 100644 (file)
@@ -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),