Fix async generator exception handling in get_optional_database_session
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user