Fix async context manager usage in BackgroundLoaderService
- Changed 'async for' to 'async with' for get_db_session() - get_db_session() is @asynccontextmanager, requires async with not async for - Created 5 comprehensive unit tests verifying the fix - All tests pass, background loading now works correctly
This commit is contained in:
@@ -4,11 +4,12 @@ Unit tests for dependency exception handling in FastAPI dependencies.
|
||||
This module tests that async generator dependencies properly handle exceptions
|
||||
thrown back into them, preventing the "generator didn't stop after athrow()" error.
|
||||
"""
|
||||
import pytest
|
||||
from fastapi import FastAPI, HTTPException, Depends
|
||||
from httpx import AsyncClient, ASGITransport
|
||||
from typing import AsyncGenerator, Optional
|
||||
|
||||
import pytest
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_optional_database_session_handles_http_exception():
|
||||
@@ -18,7 +19,7 @@ async def test_get_optional_database_session_handles_http_exception():
|
||||
that occurred when an HTTPException was raised after yielding a database session.
|
||||
"""
|
||||
from src.server.utils.dependencies import get_optional_database_session
|
||||
|
||||
|
||||
# Create a test app
|
||||
app = FastAPI()
|
||||
|
||||
@@ -48,7 +49,7 @@ async def test_get_database_session_handles_http_exception():
|
||||
that occurred when an HTTPException was raised after yielding a database session.
|
||||
"""
|
||||
from src.server.utils.dependencies import get_database_session
|
||||
|
||||
|
||||
# Create a test app
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user