]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Modified Column.copy() to use _constructor(),
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Sep 2011 00:51:58 +0000 (20:51 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 24 Sep 2011 00:51:58 +0000 (20:51 -0400)
    which defaults to self.__class__, in order to
    create the new object.  This allows easier support
    of subclassing Column.  [ticket:2284]

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

diff --git a/CHANGES b/CHANGES
index 598b8be67273da02c2d8b6c97230d5f79b09da7a..1f5cd15bdae5948c1ab3b4ed72592d970c613641 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -133,6 +133,11 @@ CHANGES
     [ticket:2270].  Also in 0.6.9.
 
 - schema
+  - Modified Column.copy() to use _constructor(), 
+    which defaults to self.__class__, in order to 
+    create the new object.  This allows easier support
+    of subclassing Column.  [ticket:2284]
+
   - Added a slightly nicer __repr__() to SchemaItem
     classes.  Note the repr here can't fully support
     the "repr is the constructor" idea since schema
index 8fd4e75781b99f3513dbeb6fb92c2a1b1cfa4845..99c8acbfe28419b4fcd1deac057bb9ff36286b36 100644 (file)
@@ -990,7 +990,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]
 
-        c = Column(
+        c = self._constructor(
                 name=self.name, 
                 type_=self.type, 
                 key = self.key, 
index 2107a3a77de30a522de5f080d6b08341c6135843..1f3a8e5c699165ebd6475d60cb027bbfb2b6a272 100644 (file)
@@ -69,6 +69,21 @@ class MetaDataTest(fixtures.TestBase, ComparesTables):
                 assert a1 is not a2
                 eq_(a2._colspec, 'bat.blah')
 
+    def test_col_subclass_copy(self):
+        class MyColumn(schema.Column):
+            def __init__(self, *args, **kw):
+                self.widget = kw.pop('widget', None)
+                super(MyColumn, self).__init__(*args, **kw)
+
+            def copy(self, *arg, **kw):
+                c = super(MyColumn, self).copy(*arg, **kw)
+                c.widget = self.widget
+                return c
+        c1 = MyColumn('foo', Integer, widget='x')
+        c2 = c1.copy()
+        assert isinstance(c2, MyColumn)
+        eq_(c2.widget, 'x')
+
     def test_uninitialized_column_copy_events(self):
         msgs = []
         def write(c, t):