]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed column.copy() to copy defaults and onupdates.
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Aug 2009 19:00:55 +0000 (19:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 28 Aug 2009 19:00:55 +0000 (19:00 +0000)
[ticket:1373]

CHANGES
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/schema.py
lib/sqlalchemy/test/testing.py
test/engine/test_metadata.py

diff --git a/CHANGES b/CHANGES
index 3ff1ee032b5ead9a6c6afd9bb16d87b912ad44eb..2c33b78618b108c28af4577b7d4467621e1696f4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -65,6 +65,9 @@ CHANGES
       is old stuff.  [ticket:1486]
       
 - sql
+    - Fixed column.copy() to copy defaults and onupdates.
+      [ticket:1373]
+
     - Fixed a bug in extract() introduced in 0.5.4 whereby
       the string "field" argument was getting treated as a 
       ClauseElement, causing various errors within more 
index 078056a01c4272bdedac424871ce655ab163bad4..46b4c498b8e320f44961878cf0929043b6c89c7c 100644 (file)
@@ -641,7 +641,7 @@ class Mapper(object):
                     # when using the declarative layer
                     self._post_configure_properties()
                     return
-                _already_compiling = True
+#                _already_compiling = True
                 try:
 
                     # double-check inside mutex
index e641f119b349b1cf30f52cb9603f3bbab8b637aa..7ba835cc4464390f1ca89be6f4e727677c42c5b2 100644 (file)
@@ -723,7 +723,21 @@ class Column(SchemaItem, expression.ColumnClause):
         This is used in ``Table.tometadata``.
 
         """
-        return Column(self.name, self.type, self.default, key = self.key, primary_key = self.primary_key, nullable = self.nullable, quote=self.quote, index=self.index, autoincrement=self.autoincrement, *[c.copy(**kw) for c in self.constraints])
+        return Column(
+                self.name, 
+                self.type, 
+                self.default, 
+                key = self.key, 
+                primary_key = self.primary_key, 
+                nullable = self.nullable, 
+                quote=self.quote, 
+                index=self.index, 
+                autoincrement=self.autoincrement, 
+                default=self.default,
+                server_default=self.server_default,
+                onupdate=self.onupdate,
+                server_onupdate=self.server_onupdate,
+                *[c.copy(**kw) for c in self.constraints])
 
     def _make_proxy(self, selectable, name=None):
         """Create a *proxy* for this column.
index 36c7d340a3bc8f80a3fe98cf1e6ce1442928294e..c7afcf0b0df02cb4de1cd688a292b311b38a4ffc 100644 (file)
@@ -580,15 +580,6 @@ class ComparesTables(object):
                 eq_(c.type.length, reflected_c.type.length)
 
             eq_(set([f.column.name for f in c.foreign_keys]), set([f.column.name for f in reflected_c.foreign_keys]))
-            if c.default:
-                assert isinstance(reflected_c.server_default,
-                                  schema.FetchedValue)
-            elif against(('mysql', '<', (5, 0))):
-                # ignore reflection of bogus db-generated DefaultClause()
-                pass
-            elif not c.primary_key or not against('postgres'):
-                print repr(c)
-                assert reflected_c.default is None, reflected_c.default
 
         assert len(table.primary_key) == len(reflected_table.primary_key)
         for c in table.primary_key:
index ca4fbaa48a525087666d4a442ede79e6de397c58..8680f31ea938ef024e1a099f6ec8a626913d87b3 100644 (file)
@@ -46,6 +46,8 @@ class MetaDataTest(TestBase, ComparesTables):
         table = Table('mytable', meta,
             Column('myid', Integer, primary_key=True),
             Column('name', String(40), nullable=True),
+            Column('foo', String(40), nullable=False, server_default='x', server_onupdate='q'),
+            Column('bar', String(40), nullable=False, default='y', onupdate='z'),
             Column('description', String(30), CheckConstraint("description='hi'")),
             UniqueConstraint('name'),
             test_needs_fk=True,
@@ -83,7 +85,7 @@ class MetaDataTest(TestBase, ComparesTables):
 
         meta.create_all(testing.db)
         try:
-            for test, has_constraints in ((test_to_metadata, True), (test_pickle, True), (test_pickle_via_reflect, False)):
+            for test, has_constraints, reflect in ((test_to_metadata, True, False), (test_pickle, True, False),(test_pickle_via_reflect, False, True)):
                 table_c, table2_c = test()
                 self.assert_tables_equal(table, table_c)
                 self.assert_tables_equal(table2, table2_c)
@@ -92,7 +94,13 @@ class MetaDataTest(TestBase, ComparesTables):
                 assert table.primary_key is not table_c.primary_key
                 assert list(table2_c.c.myid.foreign_keys)[0].column is table_c.c.myid
                 assert list(table2_c.c.myid.foreign_keys)[0].column is not table.c.myid
-
+                assert 'x' in str(table_c.c.foo.server_default.arg)
+                
+                if not reflect:
+                    assert str(table_c.c.foo.server_onupdate.arg) == 'q'
+                    assert str(table_c.c.bar.default.arg) == 'y'
+                    assert getattr(table_c.c.bar.onupdate.arg, 'arg', table_c.c.bar.onupdate.arg) == 'z'
+                
                 # constraints dont get reflected for any dialect right now
                 if has_constraints:
                     for c in table_c.c.description.constraints: