From: Mike Bayer Date: Sat, 8 Jan 2011 20:24:20 +0000 (-0500) Subject: - CheckConstraint will copy its 'initially', 'deferrable', X-Git-Tag: rel_0_6_6~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbd79ce35c56571a87a04e63fd662f017b0bef03;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - CheckConstraint will copy its 'initially', 'deferrable', and '_create_rule' attributes within a copy()/tometadata() [ticket:2000] --- diff --git a/CHANGES b/CHANGES index 46ce7c1932..86a1e98bad 100644 --- a/CHANGES +++ b/CHANGES @@ -99,6 +99,10 @@ CHANGES to int, for DBAPIs such as pymssql that naively call str() on values. + - CheckConstraint will copy its 'initially', 'deferrable', + and '_create_rule' attributes within a copy()/tometadata() + [ticket:2000] + - engine - The "unicode warning" against non-unicode bind data is now raised only when the diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index d83a4fa424..af0c762007 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -1657,7 +1657,11 @@ class CheckConstraint(Constraint): __visit_name__ = property(__visit_name__) def copy(self, **kw): - return CheckConstraint(self.sqltext, name=self.name) + return CheckConstraint(self.sqltext, + name=self.name, + initially=self.initially, + deferrable=self.deferrable, + _create_rule=self._create_rule) class ForeignKeyConstraint(Constraint): """A table-level FOREIGN KEY constraint. diff --git a/test/engine/test_metadata.py b/test/engine/test_metadata.py index b6a718a6c0..e32af57d95 100644 --- a/test/engine/test_metadata.py +++ b/test/engine/test_metadata.py @@ -123,6 +123,20 @@ class MetaDataTest(TestBase, ComparesTables): eq_(getattr(fk1c, k), kw[k]) eq_(getattr(fk2c, k), kw[k]) + def test_check_constraint_copy(self): + r = lambda x: x + c = CheckConstraint("foo bar", + name='name', + initially=True, + deferrable=True, + _create_rule = r) + c2 = c.copy() + eq_(c2.name, 'name') + eq_(str(c2.sqltext), "foo bar") + eq_(c2.initially, True) + eq_(c2.deferrable, True) + assert c2._create_rule is r + def test_fk_construct(self): c1 = Column('foo', Integer) c2 = Column('bar', Integer)