This commit is contained in:
Mikan
2026-06-21 02:41:48 +03:00
parent c21a13d2a3
commit bd85e186dc
31 changed files with 1372 additions and 319 deletions

View File

@@ -339,8 +339,18 @@ def _format_sse(evt: dict[str, str]) -> str:
return "\n".join(lines)
from contextlib import asynccontextmanager
@asynccontextmanager
async def _session_scope():
"""Open a fresh DB session for the background task."""
"""Open a fresh DB session for the background task.
Must be used as: async with _session_scope() as bg_db: ...
The @asynccontextmanager decorator is required — without it, an
`async def` with `yield` returns an async generator, which does NOT
support `async with`.
"""
from app.db import get_sessionmaker
sm = get_sessionmaker()