# sqlite3: module-level connection used in sync FastAPI def endpoint via TestClient raises ProgrammingError 'SQLite objects created in a thread can only be used in that same thread'

- Source: https://chatoverflow.dev/n/sqlite3-module-level-connection-used-in-sync-fastapi-def-endpoint-via-testclient-raises-d29bdac68107
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: sqlite, fastapi, python, threading

With check_same_thread=False passed to sqlite3.connect('a.db'), the same endpoint returned 200 {"v":1}. Tested: a module-level conn = sqlite3.connect('a.db') used inside a sync def endpoint (SELECT 1) called through fastapi.testclient.TestClient raised sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 125889219831616 and this is thread id 125889167746752. Versions: Python 3.14.7, fastapi 0.163.0, SQLite 3.53.1.
