From: Mike Bayer Date: Sat, 16 Feb 2013 01:20:50 +0000 (-0500) Subject: Fixed bug whereby create_index() X-Git-Tag: rel_0_5_0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c964b401c7c35c13586b870a24dcd1300a82da56;p=thirdparty%2Fsqlalchemy%2Falembic.git Fixed bug whereby create_index() would include in the constraint columns that are added to all Table objects using events, externally to the generation of the constraint. This is the same issue that was fixed for unique constraints in version 0.3.2. --- diff --git a/alembic/operations.py b/alembic/operations.py index f5640c5b..f97ec6e6 100644 --- a/alembic/operations.py +++ b/alembic/operations.py @@ -113,7 +113,7 @@ class Operations(object): *[sa_schema.Column(n, NULLTYPE) for n in columns], schema=schema ) - return sa_schema.Index(name, *list(t.c), **kw) + return sa_schema.Index(name, *[t.c[n] for n in columns], **kw) def _parse_table_key(self, table_key): if '.' in table_key: diff --git a/docs/build/changelog.rst b/docs/build/changelog.rst index f092c50e..f3ee4a6d 100644 --- a/docs/build/changelog.rst +++ b/docs/build/changelog.rst @@ -6,6 +6,16 @@ Changelog .. changelog:: :version: 0.5.0 + .. change:: + :tags: bug + + Fixed bug whereby create_index() + would include in the constraint columns that + are added to all Table objects using events, + externally to the generation of the constraint. + This is the same issue that was fixed for unique + constraints in version 0.3.2. + .. change:: :tags: bug :pullreq: 27 diff --git a/tests/test_op.py b/tests/test_op.py index 438a5476..d5a6abe9 100644 --- a/tests/test_op.py +++ b/tests/test_op.py @@ -6,6 +6,12 @@ from sqlalchemy import Integer, Column, ForeignKey, \ Table, String, Boolean from sqlalchemy.sql import column, func +from sqlalchemy import event +@event.listens_for(Table, "after_parent_attach") +def _add_cols(table, metadata): + if table.name == "tbl_with_auto_appended_column": + table.append_column(Column('bat', Integer)) + def test_rename_table(): context = op_fixture() @@ -405,21 +411,6 @@ def test_add_unique_constraint_schema(): "ALTER TABLE foo.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() @@ -442,6 +433,25 @@ def test_create_index(): "CREATE INDEX ik_test ON t1 (foo, bar)" ) + +def test_create_index_table_col_event(): + context = op_fixture() + + op.create_index('ik_test', 'tbl_with_auto_appended_column', ['foo', 'bar']) + context.assert_( + "CREATE INDEX ik_test ON tbl_with_auto_appended_column (foo, bar)" + ) + +def test_add_unique_constraint_col_event(): + context = op_fixture() + op.create_unique_constraint('ik_test', + 'tbl_with_auto_appended_column', ['foo', 'bar']) + context.assert_( + "ALTER TABLE tbl_with_auto_appended_column " + "ADD CONSTRAINT ik_test UNIQUE (foo, bar)" + ) + + def test_create_index_schema(): context = op_fixture() op.create_index('ik_test', 't1', ['foo', 'bar'], schema='foo')