From dbd79ce35c56571a87a04e63fd662f017b0bef03 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sat, 8 Jan 2011 15:24:20 -0500 Subject: [PATCH] - CheckConstraint will copy its 'initially', 'deferrable', and '_create_rule' attributes within a copy()/tometadata() [ticket:2000] --- CHANGES | 4 ++++ lib/sqlalchemy/schema.py | 6 +++++- test/engine/test_metadata.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) 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) -- 2.47.2