]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
check index_list pragma for number of columns returned
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 12 Dec 2022 23:05:07 +0000 (18:05 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 13 Dec 2022 14:50:12 +0000 (09:50 -0500)
Fixed regression caused by new support for reflection of partial indexes on
SQLite added in 1.4.45 for :ticket:`8804`, where the ``index_list`` pragma
command in very old versions of SQLite (possibly prior to 3.8.9) does not
return the current expected number of columns, leading to exceptions raised
when reflecting tables and indexes.

Fixes: #8969
Change-Id: If317cdcfc6782f7e180df329b6ea0ddb48ce2269
(cherry picked from commit e026a0f3562bec5fbc18e223176be8121c147193)

doc/build/changelog/unreleased_14/8969.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py
test/requirements.py

diff --git a/doc/build/changelog/unreleased_14/8969.rst b/doc/build/changelog/unreleased_14/8969.rst
new file mode 100644 (file)
index 0000000..8458706
--- /dev/null
@@ -0,0 +1,10 @@
+.. change::
+    :tags: bug, sqlite
+    :tickets: 8969
+    :versions: 2.0.0b5
+
+    Fixed regression caused by new support for reflection of partial indexes on
+    SQLite added in 1.4.45 for :ticket:`8804`, where the ``index_list`` pragma
+    command in very old versions of SQLite (possibly prior to 3.8.9) does not
+    return the current expected number of columns, leading to exceptions raised
+    when reflecting tables and indexes.
index f75610553cb44f1e4c5546cd385847198cd2a3c6..56294f4bd54daaba109d9b4091be8d810ebfd87a 100644 (file)
@@ -2518,7 +2518,7 @@ class SQLiteDialect(default.DefaultDialect):
             )
 
             # check partial indexes
-            if row[4]:
+            if len(row) >= 5 and row[4]:
                 s = (
                     "SELECT sql FROM %(schema)ssqlite_master "
                     "WHERE name = ? "
index 01ba416480385fd93afbdad1b277c670f192ba4d..418bf9c6575f8bcb2d82d8c170ca7ff88bbe047d 100644 (file)
@@ -2392,6 +2392,7 @@ class ConstraintReflectionTest(fixtures.TestBase):
             ],
         )
 
+    @testing.requires.sqlite_partial_indexes
     def test_reflect_partial_indexes(self, connection):
         connection.exec_driver_sql(
             "create table foo_with_partial_index (x integer, y integer)"
index 55c3383a42f5e7b031a09117883ad0ebbd118212..fa9ba88f58f8e77fb1c4e9003487ddc8e7dae3e6 100644 (file)
@@ -1128,6 +1128,30 @@ class DefaultRequirements(SuiteRequirements):
     def sqlite_memory(self):
         return only_on(self._sqlite_memory_db)
 
+    def _sqlite_partial_idx(self, config):
+        if not against(config, "sqlite"):
+            return False
+        else:
+            with config.db.connect() as conn:
+                connection = conn.connection
+                cursor = connection.cursor()
+                try:
+                    cursor.execute("SELECT * FROM pragma_index_info('idx52')")
+                except:
+                    return False
+                else:
+                    return (
+                        cursor.description is not None
+                        and len(cursor.description) >= 3
+                    )
+                finally:
+                    cursor.close()
+
+    @property
+    def sqlite_partial_indexes(self):
+
+        return only_on(self._sqlite_partial_idx)
+
     @property
     def reflects_json_type(self):
         return only_on(