Format updates to instructions and test file

- Improve markdown formatting in instructions.md
- Reorder imports in test_background_loader_session.py per PEP8
This commit is contained in:
2026-01-19 20:06:03 +01:00
parent 7d95c180a9
commit d6a82f4329
2 changed files with 11 additions and 5 deletions

View File

@@ -121,10 +121,11 @@ For each task completed:
**Task Completed Successfully**
### Issue Fixed: TypeError: 'async for' requires an object with __aiter__ method
### Issue Fixed: TypeError: 'async for' requires an object with **aiter** method
**Problem:**
The BackgroundLoaderService was crashing when trying to load series data with the error:
```
TypeError: 'async for' requires an object with __aiter__ method, got _AsyncGeneratorContextManager
```
@@ -136,6 +137,7 @@ The code was incorrectly using `async for db in get_db_session():` to get a data
**Solution:**
Changed the database session acquisition from:
```python
async for db in get_db_session():
# ... code ...
@@ -143,16 +145,19 @@ async for db in get_db_session():
```
To the correct pattern:
```python
async with get_db_session() as db:
# ... code ...
```
**Files Modified:**
1. [src/server/services/background_loader_service.py](src/server/services/background_loader_service.py) - Fixed async context manager usage
2. [tests/unit/test_background_loader_session.py](tests/unit/test_background_loader_session.py) - Created comprehensive unit tests
**Tests:**
- ✅ 5 new unit tests for background loader database session handling (all passing)
- ✅ Tests verify proper async context manager usage
- ✅ Tests verify error handling and progress tracking

View File

@@ -4,14 +4,15 @@ Unit tests for BackgroundLoaderService database session handling.
This module tests that the background loader service properly uses async context
managers for database sessions, preventing TypeError with async for.
"""
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
from datetime import datetime, timezone
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from src.server.services.background_loader_service import (
BackgroundLoaderService,
SeriesLoadingTask,
LoadingStatus,
SeriesLoadingTask,
)
@@ -277,7 +278,7 @@ async def test_async_context_manager_usage():
"""
from contextlib import asynccontextmanager
from typing import AsyncGenerator
# Create a test async context manager
call_log = []