From 56f16e30b494d6e58664ea4d66aa07c234398c54 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Wed, 16 Nov 2022 17:17:26 +0900 Subject: [PATCH] add exception handling --- lib/sqlalchemy/dialects/sqlite/base.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index d6defa41df..000ae8b41a 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -2684,11 +2684,21 @@ class SQLiteDialect(default.DefaultDialect): "AND type = 'index'" % {"schema": schema_expr} ) rs = connection.exec_driver_sql(s, (row[1],)) - index_sql = rs.scalar() - predicate = partial_pred_re.search(index_sql).group(1) - indexes[-1]["dialect_options"]["sqlite_where"] = text( - predicate - ) + try: + # in theory the code below shouldn't happen because + # we know this is a partial index, so the definition + # sql should be there and match the regex + index_sql = rs.scalar() + predicate = partial_pred_re.search(index_sql).group(1) + indexes[-1]["dialect_options"]["sqlite_where"] = text( + predicate + ) + except Exception: + util.warn( + "Failed to look up filter predicate of " + "partial index %s" % row[1] + ) + indexes.pop() # loop thru unique indexes to get the column names. for idx in list(indexes): -- 2.47.3