Fix: Scanner availability for series addition

- Change 'scanner' to 'serie_scanner' attribute name
- Update tests to match SeriesApp attribute naming
- Scanner now properly detected and called on add
- All add_series tests passing (9/9)
This commit is contained in:
Lukas 2026-01-11 17:48:37 +01:00
parent 5c0a019e72
commit 281b982abe
3 changed files with 31 additions and 40 deletions

View File

@ -108,47 +108,40 @@ For each task completed:
## TODO List:
### Task: Refactor Series Addition and Folder Creation Logic
### Task: Fix Scanner Availability for Series Addition
**Priority:** High
**Status:** ✅ Complete
#### Overview
#### Problem
After adding a series, the targeted scan was being skipped with the message:
```
INFO: Scanner not directly available, skipping targeted scan for romantic-killer
```
Refactored the series addition workflow to defer folder creation until download time and ensure proper series scanning on addition. This improves the separation of concerns and ensures a cleaner workflow.
#### Root Cause
The code was checking for `series_app.scanner`, but the actual attribute name in SeriesApp is `serie_scanner`.
#### Completed Changes
#### Changes Made
1. **Folder Creation Removed from Series Addition**
- Modified [src/server/api/anime.py](../src/server/api/anime.py) to remove folder creation on series add
- Series are now only added to the database and in-memory structures
- Folder creation is deferred to download time
1. **Fixed [src/server/api/anime.py](../src/server/api/anime.py)**:
- Changed `hasattr(series_app, "scanner")` to `hasattr(series_app, "serie_scanner")`
- Changed `series_app.scanner.scan_single_series()` to `series_app.serie_scanner.scan_single_series()`
- Updated fallback message to be a warning instead of info
2. **Folder Creation Added to Download Start**
- Updated [src/core/SeriesApp.py](../src/core/SeriesApp.py) `download()` method
- Added folder existence check before download
- Creates folder if it doesn't exist using the series folder name
- Includes proper error handling and logging
3. **Database Persistence Maintained**
- Series are still properly saved to the database on addition
- No regression in database entry creation
4. **Targeted Scanning Works**
- Scan logic continues to work correctly
- Only the added series is scanned (not full library rescan)
- Works correctly even when folder doesn't exist yet
2. **Fixed [tests/api/test_anime_endpoints.py](../tests/api/test_anime_endpoints.py)**:
- Changed `self.scanner = FakeScanner()` to `self.serie_scanner = FakeScanner()`
- Added comment explaining the attribute name matches SeriesApp
#### Test Results
- ✅ All 9 add_series endpoint tests passing
- ✅ Scanner is now correctly detected and called
- ✅ Targeted scanning works when adding series
- All add_series endpoint tests passing (9/9)
- All SeriesApp download tests passing (4/4)
- Total: 1132 tests passing (up from 1123 before changes)
- Remaining failures are unrelated to these changes (scan_service, download_service issues)
#### Note on Year Attribute
Year information is not currently available in the Serie class or search results. The folder naming currently uses just the series name without the year suffix. This can be enhanced in a future task when year metadata is added to the system.
#### Expected Behavior After Fix
When adding a series, you should now see:
```
INFO: Targeted scan completed for romantic-killer: found X missing episodes
```
---

View File

@ -761,8 +761,8 @@ async def add_series(
# Step E: Trigger targeted scan for missing episodes
try:
if series_app and hasattr(series_app, "scanner"):
missing_episodes = series_app.scanner.scan_single_series(
if series_app and hasattr(series_app, "serie_scanner"):
missing_episodes = series_app.serie_scanner.scan_single_series(
key=key,
folder=folder
)
@ -776,12 +776,10 @@ async def add_series(
if hasattr(series_app, "list") and hasattr(series_app.list, "keyDict"):
if key in series_app.list.keyDict:
series_app.list.keyDict[key].episodeDict = missing_episodes
elif anime_service:
# Fallback to anime_service if scanner not directly available
# Note: This is a lightweight scan, not a full rescan
logger.info(
"Scanner not directly available, "
"skipping targeted scan for %s",
else:
# Scanner not available - this shouldn't happen in normal operation
logger.warning(
"Scanner not available for targeted scan of %s",
key
)
except Exception as e:

View File

@ -42,7 +42,7 @@ class FakeSeriesApp:
def __init__(self):
"""Initialize fake series app."""
self.list = self # Changed from self.List to self.list
self.scanner = FakeScanner() # Add fake scanner
self.serie_scanner = FakeScanner() # Add fake scanner (matches SeriesApp attribute name)
self.directory = "/tmp/fake_anime"
self.keyDict = {} # Add keyDict for direct access
self._items = [