]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix a reflection error for MSSQL 2005
authorFederico Caselli <cfederico87@gmail.com>
Thu, 18 Feb 2021 17:57:02 +0000 (18:57 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 18 Feb 2021 17:57:02 +0000 (18:57 +0100)
The reflection of filtered indexes broke index reflection error
for MSSQL 2005 that does not support that them

Fixes #5930

Change-Id: I5d1f4fa8ba5bca31e91981076e4ee476ddfba49a

doc/build/changelog/unreleased_14/5930.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mssql/base.py

diff --git a/doc/build/changelog/unreleased_14/5930.rst b/doc/build/changelog/unreleased_14/5930.rst
new file mode 100644 (file)
index 0000000..7751a2b
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, mssql
+    :tickets: 5919
+
+    Fix a reflection error for MSSQL 2005 introduced by the reflection of
+    filtered indexes.
index a0aa67c69a6a59ce1524e600262ac20390b5ff87..81f66e2f09b16721bbd4fcdf19112a92dfaa62b1 100644 (file)
@@ -2894,16 +2894,22 @@ class MSDialect(default.DefaultDialect):
     @reflection.cache
     @_db_plus_owner
     def get_indexes(self, connection, tablename, dbname, owner, schema, **kw):
+        filter_definition = (
+            "ind.filter_definition"
+            if self.server_version_info >= MS_2008_VERSION
+            else "NULL as filter_definition"
+        )
         rp = connection.execution_options(future_result=True).execute(
             sql.text(
                 "select ind.index_id, ind.is_unique, ind.name, "
-                "ind.filter_definition "
+                "%s "
                 "from sys.indexes as ind join sys.tables as tab on "
                 "ind.object_id=tab.object_id "
                 "join sys.schemas as sch on sch.schema_id=tab.schema_id "
                 "where tab.name = :tabname "
                 "and sch.name=:schname "
                 "and ind.is_primary_key=0 and ind.type != 0"
+                % filter_definition
             )
             .bindparams(
                 sql.bindparam("tabname", tablename, ischema.CoerceUnicode()),