From 219af6eb3d9d3cd00a6145339feb1ea12f99cf22 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Mon, 21 Nov 2022 14:38:35 +0900 Subject: [PATCH] use 'is None' check for regex match --- lib/sqlalchemy/dialects/sqlite/base.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 000ae8b41a..1061d8cd96 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -2684,21 +2684,21 @@ class SQLiteDialect(default.DefaultDialect): "AND type = 'index'" % {"schema": schema_expr} ) rs = connection.exec_driver_sql(s, (row[1],)) - 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: + index_sql = rs.scalar() + predicate_match = partial_pred_re.search(index_sql) + if predicate_match is None: + # unless the regex is broken this case shouldn't happen + # because we know this is a partial index, so the + # definition sql should match the regex util.warn( "Failed to look up filter predicate of " "partial index %s" % row[1] ) - indexes.pop() + else: + predicate = predicate_match.group(1) + indexes[-1]["dialect_options"]["sqlite_where"] = text( + predicate + ) # loop thru unique indexes to get the column names. for idx in list(indexes): -- 2.47.3