]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Check for mssql_include is None
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Nov 2018 18:53:57 +0000 (13:53 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 14 Nov 2018 19:00:22 +0000 (14:00 -0500)
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
docs/build/unreleased/516.rst [new file with mode: 0644]
tests/test_mssql.py

index bf6f5e92b4b56d2630d677a07157e181766b11d8..f303be480ad888f3a5dd4614ef824454f515168a 100644 (file)
@@ -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 (file)
index 0000000..6884448
--- /dev/null
@@ -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.
index a5e013eee135d357f43ecd0b6f906a75e751fd5a..b092dcf6e2e7a13e54ca653e0c724ba9ac7bc413 100644 (file)
@@ -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)")