From 174cb4bf39ed2e5c68258bcb2e04a75ae09bcc4e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 14 Nov 2018 13:53:57 -0500 Subject: [PATCH] Check for mssql_include is None Fixed regression caused by :ticket:`513`, where the logic to consume ``mssql_include`` was not correctly interpreting the case where the flag was not present, breaking the ``op.create_index`` directive for SQL Server as a whole. Change-Id: I4c3a9d1f12017b62a7affa3863bba6e2bead67cf Fixes: #516 --- alembic/ddl/mssql.py | 5 ++++- docs/build/unreleased/516.rst | 8 ++++++++ tests/test_mssql.py | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 docs/build/unreleased/516.rst diff --git a/alembic/ddl/mssql.py b/alembic/ddl/mssql.py index bf6f5e92..f303be48 100644 --- a/alembic/ddl/mssql.py +++ b/alembic/ddl/mssql.py @@ -90,7 +90,10 @@ class MSSQLImpl(DefaultImpl): name=name) def create_index(self, index): - mssql_include = index.kwargs.get('mssql_include', ()) + # this likely defaults to None if not present, so get() + # should normally not return the default value. being + # defensive in any case + mssql_include = index.kwargs.get('mssql_include', None) or () for col in mssql_include: if col not in index.table.c: index.table.append_column(Column(col, sqltypes.NullType)) diff --git a/docs/build/unreleased/516.rst b/docs/build/unreleased/516.rst new file mode 100644 index 00000000..6884448e --- /dev/null +++ b/docs/build/unreleased/516.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, mssql + :tickets: 516 + + Fixed regression caused by :ticket:`513`, where the logic to consume + ``mssql_include`` was not correctly interpreting the case where the flag + was not present, breaking the ``op.create_index`` directive for SQL Server + as a whole. diff --git a/tests/test_mssql.py b/tests/test_mssql.py index a5e013ee..b092dcf6 100644 --- a/tests/test_mssql.py +++ b/tests/test_mssql.py @@ -284,3 +284,12 @@ class OpTest(TestBase): context.assert_contains( "CREATE INDEX ix_mytable_a_b ON mytable " "(col_a, col_b) INCLUDE (col_c)") + + def test_create_index_mssql_include_is_none(self): + context = op_fixture('mssql') + op.create_index( + op.f('ix_mytable_a_b'), 'mytable', ['col_a', 'col_b'], + unique=False) + context.assert_contains( + "CREATE INDEX ix_mytable_a_b ON mytable " + "(col_a, col_b)") -- 2.47.2