]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- [bug] Fixed bug whereby create_unique_constraint()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Apr 2012 22:07:06 +0000 (18:07 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Apr 2012 22:07:06 +0000 (18:07 -0400)
  would include in the constraint columns that
  are added to all Table objects using events,
  externally to the generation of the constraint.

CHANGES
alembic/operations.py
tests/test_op.py

diff --git a/CHANGES b/CHANGES
index 0f980847c4ebe27086e5910b878c475e40521189..241c57ac88e678d1f89ce27aa33be919c4ba2929 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,11 @@
   ForeignKey target in column alter operations,
   courtesy Alexander Kolov.
 
+- [bug] Fixed bug whereby create_unique_constraint()
+  would include in the constraint columns that
+  are added to all Table objects using events,
+  externally to the generation of the constraint.
+
 0.3.1
 =====
 - [bug] bulk_insert() fixes:
index ece624868ea3d419418821ca5079f77e0334e305..7787f77a24fc8e087fa3b602bee0f5f4d0cdf234 100644 (file)
@@ -74,7 +74,7 @@ class Operations(object):
         t = schema.Table(source, schema.MetaData(), 
                     *[schema.Column(n, NULLTYPE) for n in local_cols])
         kw['name'] = name
-        uq = schema.UniqueConstraint(*t.c, **kw)
+        uq = schema.UniqueConstraint(*[t.c[n] for n in local_cols], **kw)
         # TODO: need event tests to ensure the event
         # is fired off here
         t.append_constraint(uq)
index 71d78d95db544500a2627505508e353b7465aa25..58c560d6fbf38467665edf04f69dbfd11b3d6e07 100644 (file)
@@ -201,6 +201,22 @@ def test_add_unique_constraint():
         "ALTER TABLE t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
     )
 
+def test_add_unique_constraint_auto_cols():
+    context = op_fixture()
+    from sqlalchemy import event, DateTime
+
+    @event.listens_for(Table, "after_parent_attach")
+    def _table_standard_cols(table, metadata):
+        table.append_column(Column('created_at', DateTime))
+
+    try:
+        op.create_unique_constraint('uk_test', 't1', ['foo', 'bar'])
+        context.assert_(
+            "ALTER TABLE t1 ADD CONSTRAINT uk_test UNIQUE (foo, bar)"
+        )
+    finally:
+        Table.dispatch._clear()
+
 def test_drop_constraint():
     context = op_fixture()
     op.drop_constraint('foo_bar_bat', 't1')