From e0f8eeeaa77b581756d32f6525374695610d3c37 Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 10 Oct 2023 10:30:52 -0400 Subject: [PATCH] Improve search.backends.sqlite retry logic Retry with table creation should fail if it is attempted for a second time. --- archivebox/search/backends/sqlite.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/archivebox/search/backends/sqlite.py b/archivebox/search/backends/sqlite.py index ef93522f..b2c75bba 100644 --- a/archivebox/search/backends/sqlite.py +++ b/archivebox/search/backends/sqlite.py @@ -129,14 +129,16 @@ def index(snapshot_id: str, texts: List[str]): "INSERT OR REPLACE INTO" f" {table}(rowid, {column}) VALUES ({SQLITE_BIND}, {SQLITE_BIND})", [rowid, text]) - # All statements succeeded; break retry loop - break + # All statements succeeded; return + return except Exception as e: - if str(e).startswith(f"no such table:"): + if str(e).startswith("no such table:") and retries > 0: _create_tables() else: raise + raise RuntimeError("Failed to create tables for SQLite FTS5 search") + @enforce_types def search(text: str) -> List[str]: table = _escape_sqlite3_identifier(FTS_TABLE)