diff --git a/parentcalendar/db.py b/parentcalendar/db.py index dde3490..5c14d79 100644 --- a/parentcalendar/db.py +++ b/parentcalendar/db.py @@ -12,7 +12,9 @@ BOOL_COLUMNS = {"double_read", "all_day", "applies", "include", "no_lunch"} def connect(path=None): - conn = sqlite3.connect(path or config.DB_PATH, timeout=30) + # FastAPI may open a request's connection in one worker thread and run the endpoint in another. + # Each connection still serves one request (or the worker) at a time, so crossing threads is safe. + conn = sqlite3.connect(path or config.DB_PATH, timeout=30, check_same_thread=False) conn.row_factory = sqlite3.Row conn.execute("PRAGMA foreign_keys = ON") conn.execute("PRAGMA journal_mode = WAL")