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:
2026-01-19 19:50:25 +01:00
parent 62bdcf35cb
commit 7d95c180a9
4 changed files with 340 additions and 26 deletions

View File

@@ -279,7 +279,7 @@ class BackgroundLoaderService:
from src.server.database.connection import get_db_session
from src.server.database.service import AnimeSeriesService
async for db in get_db_session():
async with get_db_session() as db:
try:
# Check what data is missing
missing = await self.check_missing_data(
@@ -337,8 +337,6 @@ class BackgroundLoaderService:
# Broadcast error
await self._broadcast_status(task)
break # Exit async for loop after first iteration
finally:
# Remove from active tasks
self.active_tasks.pop(task.key, None)