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