Mike Bayer avatar Mike Bayer committed d936fd9

- Default generators like Sequence() translate correctly
across a copy() operation.

- Sequence() and other DefaultGenerator objects are accepted
as the value for the "default" and "onupdate" keyword
arguments of Column, in addition to being accepted
positionally.

Comments (0)

Files changed (3)

       declarative helpers which place common columns on multiple 
       subclasses.
     
+    - Default generators like Sequence() translate correctly
+      across a copy() operation.
+      
+    - Sequence() and other DefaultGenerator objects are accepted 
+      as the value for the "default" and "onupdate" keyword
+      arguments of Column, in addition to being accepted
+      positionally.  
+      
     - Fixed a column arithmetic bug that affected column
       correspondence for cloned selectables which contain
       free-standing column expressions.   This bug is

lib/sqlalchemy/schema.py

 
         toinit = list(self.args)
         if self.default is not None:
-            if isinstance(self.default, ColumnDefault):
+            if isinstance(self.default, DefaultGenerator):
                 toinit.append(self.default)
             else:
                 toinit.append(ColumnDefault(self.default))
             else:
                 toinit.append(DefaultClause(self.server_default))
         if self.onupdate is not None:
-            toinit.append(ColumnDefault(self.onupdate, for_update=True))
+            if isinstance(self.onupdate, DefaultGenerator):
+                toinit.append(self.onupdate)
+            else:
+                toinit.append(ColumnDefault(self.onupdate, for_update=True))
         if self.server_onupdate is not None:
             if isinstance(self.server_onupdate, FetchedValue):
                 toinit.append(self.server_default)

test/engine/test_metadata.py

 from sqlalchemy.test.testing import assert_raises, assert_raises_message
 import pickle
 from sqlalchemy import MetaData
-from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey, Sequence
+from sqlalchemy import Integer, String, UniqueConstraint, CheckConstraint, ForeignKey, \
+                            Sequence, ColumnDefault
 from sqlalchemy.test.schema import Table
 from sqlalchemy.test.schema import Column
 import sqlalchemy as tsa
         meta = MetaData()
 
         table = Table('mytable', meta,
-            Column('myid', Integer, primary_key=True),
+            Column('myid', Integer, Sequence('foo_id_seq'), 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'),
                 assert 'x' in str(table_c.c.foo.server_default.arg)
                 
                 if not reflect:
+                    assert isinstance(table_c.c.myid.default, Sequence)
                     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'
             assert t.info['bar'] == 'zip'
 
 class ColumnOptionsTest(TestBase):
+    
+    def test_default_generators(self):
+        g1, g2 = Sequence('foo_id_seq'), ColumnDefault('f5')
+        assert Column(default=g1).default is g1
+        assert Column(onupdate=g1).onupdate is g1
+        assert Column(default=g2).default is g2
+        assert Column(onupdate=g2).onupdate is g2
+        
+        
     def test_column_info(self):
         
         c1 = Column('foo', info={'x':'y'})
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.