diff --git a/backend/app/db.py b/backend/app/db.py index 6e4c945..c773355 100644 --- a/backend/app/db.py +++ b/backend/app/db.py @@ -53,7 +53,10 @@ CREATE TABLE IF NOT EXISTS meta ( def connect() -> sqlite3.Connection: path = get_settings().db_path os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True) - conn = sqlite3.connect(path, timeout=30) + # FastAPI may open, use and close a request's connection on different + # worker threads. Each request has its own connection used by one thread + # at a time, so the same-thread check can safely be off. + conn = sqlite3.connect(path, timeout=30, check_same_thread=False) conn.row_factory = sqlite3.Row conn.execute("PRAGMA journal_mode=WAL") conn.execute("PRAGMA synchronous=NORMAL")