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:
@@ -121,10 +121,11 @@ For each task completed:
|
|||||||
|
|
||||||
✅ **Task Completed Successfully**
|
✅ **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:**
|
**Problem:**
|
||||||
The BackgroundLoaderService was crashing when trying to load series data with the error:
|
The BackgroundLoaderService was crashing when trying to load series data with the error:
|
||||||
|
|
||||||
```
|
```
|
||||||
TypeError: 'async for' requires an object with __aiter__ method, got _AsyncGeneratorContextManager
|
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:**
|
**Solution:**
|
||||||
Changed the database session acquisition from:
|
Changed the database session acquisition from:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async for db in get_db_session():
|
async for db in get_db_session():
|
||||||
# ... code ...
|
# ... code ...
|
||||||
@@ -143,16 +145,19 @@ async for db in get_db_session():
|
|||||||
```
|
```
|
||||||
|
|
||||||
To the correct pattern:
|
To the correct pattern:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
async with get_db_session() as db:
|
async with get_db_session() as db:
|
||||||
# ... code ...
|
# ... code ...
|
||||||
```
|
```
|
||||||
|
|
||||||
**Files Modified:**
|
**Files Modified:**
|
||||||
|
|
||||||
1. [src/server/services/background_loader_service.py](src/server/services/background_loader_service.py) - Fixed async context manager usage
|
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
|
2. [tests/unit/test_background_loader_session.py](tests/unit/test_background_loader_session.py) - Created comprehensive unit tests
|
||||||
|
|
||||||
**Tests:**
|
**Tests:**
|
||||||
|
|
||||||
- ✅ 5 new unit tests for background loader database session handling (all passing)
|
- ✅ 5 new unit tests for background loader database session handling (all passing)
|
||||||
- ✅ Tests verify proper async context manager usage
|
- ✅ Tests verify proper async context manager usage
|
||||||
- ✅ Tests verify error handling and progress tracking
|
- ✅ Tests verify error handling and progress tracking
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ Unit tests for BackgroundLoaderService database session handling.
|
|||||||
This module tests that the background loader service properly uses async context
|
This module tests that the background loader service properly uses async context
|
||||||
managers for database sessions, preventing TypeError with async for.
|
managers for database sessions, preventing TypeError with async for.
|
||||||
"""
|
"""
|
||||||
import pytest
|
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from src.server.services.background_loader_service import (
|
from src.server.services.background_loader_service import (
|
||||||
BackgroundLoaderService,
|
BackgroundLoaderService,
|
||||||
SeriesLoadingTask,
|
|
||||||
LoadingStatus,
|
LoadingStatus,
|
||||||
|
SeriesLoadingTask,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -277,7 +278,7 @@ async def test_async_context_manager_usage():
|
|||||||
"""
|
"""
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
|
|
||||||
# Create a test async context manager
|
# Create a test async context manager
|
||||||
call_log = []
|
call_log = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user