open-webui/backend/open_webui
Claude 6bda95d3bd
fix(db): patch SQLAlchemy ↔ aiosqlite ≥0.20 terminate_force_close incompatibility
SQLAlchemy 2.0.36+ added a `terminate_force_close()` path on its
async DB-API adapters, used by the connection pool when a connection
must be invalidated immediately (typically when an in-flight query
was cancelled — request aborted by client, timeout, etc.).

For the aiosqlite dialect, `_terminate_force_close` unconditionally
accesses `self._connection.stop`. That attribute existed on
`aiosqlite.Connection` up to 0.18 (where Connection sub-classed
`threading.Thread`) and was removed in 0.20+ when the worker model
was refactored.

On the version pin Open WebUI ships (sqlalchemy 2.0.48 + aiosqlite
0.21.0) every cancelled aiosqlite call therefore produces a
multi-page

  NotImplementedError: terminate_force_close() not implemented by this DBAPI shim

ERROR traceback, drowning real errors in noise even though the
underlying connection is correctly torn down by aiosqlite's own
worker on the next loop tick.

Add `internal/_aiosqlite_compat.install()` which monkey-patches the
shim to understand both APIs:

  * aiosqlite ≤ 0.18 — call `Connection.stop()` as before.
  * aiosqlite ≥ 0.20 — flip the worker thread's `_running` flag so it
    exits on the next iteration (the same end-state the original code
    achieved on the old API).
  * Anything else — log at debug and fall back to GC.

The patch is idempotent, runs once at db.py import time before the
async engine is created, and is a no-op on installations whose
SQLAlchemy doesn't ship the affected symbol — so it won't break
future upstream rewrites.

https://claude.ai/code/session_01JSr4NZSskEUQvoJnavVXh8
2026-04-14 12:35:19 +00:00
..
data refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
internal fix(db): patch SQLAlchemy ↔ aiosqlite ≥0.20 terminate_force_close incompatibility 2026-04-14 12:35:19 +00:00
migrations refac 2026-04-01 18:26:46 -05:00
models refac 2026-04-13 21:29:03 -05:00
retrieval refac 2026-04-13 16:03:36 -05:00
routers refac 2026-04-13 21:29:03 -05:00
socket fix: invalidate stale Socket.IO sessions on role change and user deletion (#23642) 2026-04-12 16:19:38 -05:00
static refac 2026-03-23 23:39:52 -05:00
storage refac 2026-04-12 19:08:30 -05:00
test refac 2026-03-17 17:58:01 -05:00
tools chore: format 2026-04-12 22:11:10 -05:00
utils refac 2026-04-14 01:17:39 -05:00
__init__.py refac (#22987) 2026-03-24 15:41:26 -05:00
alembic.ini fix: Alembic CLI commands from failing 2025-08-15 04:17:47 -04:00
config.py refac 2026-04-14 00:07:50 -05:00
constants.py refac 2026-04-13 14:08:58 -05:00
env.py refac 2026-04-13 16:25:44 -05:00
functions.py refac: async db 2026-04-12 14:22:11 -05:00
main.py refac 2026-04-14 00:07:50 -05:00
tasks.py refac 2026-03-17 17:58:01 -05:00