Fix async generator exception handling in get_optional_database_session

This commit is contained in:
2026-01-23 16:06:42 +01:00
parent f8634bf605
commit faac14346f
5 changed files with 6 additions and 33 deletions

View File

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