diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-05-02 10:27:03 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2015-05-02 10:27:03 -0400 |
commit | 77db0ef6ac03d0f6f5622be373f7f85536924d3e (patch) | |
tree | 7d7bb0de993831b349a195711930e0f4a5d20bc8 /test/sql/test_constraints.py | |
parent | b2196dd953e6313fcd688530aeeccfd013c61069 (diff) | |
download | sqlalchemy-77db0ef6ac03d0f6f5622be373f7f85536924d3e.tar.gz |
- Fixed bug in enhanced constraint-attachment logic introduced in
:ticket:`3341` where in the unusual case of a constraint that refers
to a mixture of :class:`.Column` objects and string column names
at the same time, the auto-attach-on-column-attach logic will be
skipped; for the constraint to be auto-attached in this case,
all columns must be assembled on the target table up front.
Added a new section to the migration document regarding the
original feature as well as this change.
fixes #3411
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r-- | test/sql/test_constraints.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 47f81a50c..3e8021ebe 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -1347,6 +1347,65 @@ class ConstraintAPITest(fixtures.TestBase): t2.append_column, c ) + def test_auto_append_uq_on_col_attach_four(self): + """Test that a uniqueconstraint that names Column and string names + won't autoattach using deferred column attachment. + + """ + m = MetaData() + + a = Column('a', Integer) + b = Column('b', Integer) + c = Column('c', Integer) + uq = UniqueConstraint(a, 'b', 'c') + + t = Table('tbl', m, a) + assert uq not in t.constraints + + t.append_column(b) + assert uq not in t.constraints + + t.append_column(c) + + # we don't track events for previously unknown columns + # named 'c' to be attached + assert uq not in t.constraints + + t.append_constraint(uq) + + assert uq in t.constraints + + eq_( + [cn for cn in t.constraints if isinstance(cn, UniqueConstraint)], + [uq] + ) + + def test_auto_append_uq_on_col_attach_five(self): + """Test that a uniqueconstraint that names Column and string names + *will* autoattach if the table has all those names up front. + + """ + m = MetaData() + + a = Column('a', Integer) + b = Column('b', Integer) + c = Column('c', Integer) + + t = Table('tbl', m, a, c, b) + + uq = UniqueConstraint(a, 'b', 'c') + + assert uq in t.constraints + + t.append_constraint(uq) + + assert uq in t.constraints + + eq_( + [cn for cn in t.constraints if isinstance(cn, UniqueConstraint)], + [uq] + ) + def test_index_asserts_cols_standalone(self): metadata = MetaData() |