diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-12-12 18:05:07 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-12-13 09:50:12 -0500 |
commit | 7b150d43ce04a62ee83159855bdc4452ea02617a (patch) | |
tree | 18f1f33f45bb3cb93699945019db917c9b3069d6 | |
parent | 2f279ce32235a69b9db6a0048230db9c34ff70db (diff) | |
download | sqlalchemy-7b150d43ce04a62ee83159855bdc4452ea02617a.tar.gz |
check index_list pragma for number of columns returned
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)
-rw-r--r-- | doc/build/changelog/unreleased_14/8969.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 2 | ||||
-rw-r--r-- | test/dialect/test_sqlite.py | 1 | ||||
-rw-r--r-- | test/requirements.py | 24 |
4 files changed, 36 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_14/8969.rst b/doc/build/changelog/unreleased_14/8969.rst new file mode 100644 index 000000000..8458706c8 --- /dev/null +++ b/doc/build/changelog/unreleased_14/8969.rst @@ -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. diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index f75610553..56294f4bd 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -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 = ? " diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index 01ba41648..418bf9c65 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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)" diff --git a/test/requirements.py b/test/requirements.py index 55c3383a4..fa9ba88f5 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -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( |