mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-25 17:21:00 -05:00
fix: restore sync get_db_context after v0.9.5 merge
Upstream v0.9.5 dropped the sync context-manager helper from internal/db.py, but our local UserUsages and KnowledgeDrive paths still import and use it (and chats.py imports it for backward compat). Without this helper, importing open_webui.models.chats fails at startup with ImportError: cannot import name 'get_db_context'. Re-adds the original implementation: yields the passed session if DATABASE_ENABLE_SESSION_SHARING is on, otherwise opens a new one via get_db(). Made-with: Cursor
This commit is contained in:
@@ -324,6 +324,21 @@ def get_session():
|
||||
get_db = contextmanager(get_session)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_db_context(db: Optional[Session] = None):
|
||||
"""Sync context manager that reuses an existing session if provided.
|
||||
|
||||
Used by local sync paths (UserUsages, KnowledgeDrive) where rewriting to
|
||||
async would require touching call sites in middleware/routers. Mirrors
|
||||
the async ``get_async_db_context`` pattern.
|
||||
"""
|
||||
if isinstance(db, Session) and DATABASE_ENABLE_SESSION_SHARING:
|
||||
yield db
|
||||
else:
|
||||
with get_db() as session:
|
||||
yield session
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ASYNC ENGINE (used for ALL runtime database operations)
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user