Fix async generator exception handling and add comprehensive tests

This commit is contained in:
2026-01-19 20:34:06 +01:00
parent d6a82f4329
commit 6d40ddbfe5
3 changed files with 230 additions and 54 deletions

View File

@@ -170,12 +170,7 @@ async def get_optional_database_session() -> AsyncGenerator:
from src.server.database import get_db_session
async with get_db_session() as session:
try:
yield session
except Exception:
# Re-raise the exception to let FastAPI handle it
# This prevents "generator didn't stop after athrow()" error
raise
yield session
except (ImportError, RuntimeError):
# Database not available - yield None
yield None