Fix get_optional_database_session to handle uninitialized database
- Moved RuntimeError catch to encompass get_db_session() call - Previously only caught during import, not during execution - Now properly yields None when database not initialized - Fixes test_add_series_endpoint_authenticated test failure
This commit is contained in:
@@ -297,15 +297,15 @@ For each task completed:
|
||||
- **What**: Checking for poster.jpg, logo.png, fanart.jpg existence
|
||||
- **Fix**: ✅ Created `src/server/utils/media.py` utility module
|
||||
- **Status**: COMPLETED (January 24, 2026)
|
||||
- **Resolution**:
|
||||
- Created comprehensive media utilities module with functions:
|
||||
- `check_media_files()`: Check existence of standard media files
|
||||
- `get_media_file_paths()`: Get paths to existing media files
|
||||
- `has_all_images()`: Check for complete image set
|
||||
- `count_video_files()` / `has_video_files()`: Video file utilities
|
||||
- Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS`
|
||||
- Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py`
|
||||
- Functions accept both `str` and `Path` for compatibility
|
||||
- **Resolution**:
|
||||
- Created comprehensive media utilities module with functions:
|
||||
- `check_media_files()`: Check existence of standard media files
|
||||
- `get_media_file_paths()`: Get paths to existing media files
|
||||
- `has_all_images()`: Check for complete image set
|
||||
- `count_video_files()` / `has_video_files()`: Video file utilities
|
||||
- Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS`
|
||||
- Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py`
|
||||
- Functions accept both `str` and `Path` for compatibility
|
||||
|
||||
### Further Considerations (Require Architecture Decisions)
|
||||
|
||||
|
||||
@@ -165,21 +165,21 @@ async def get_optional_database_session() -> AsyncGenerator:
|
||||
"""
|
||||
try:
|
||||
from src.server.database import get_db_session
|
||||
|
||||
# Try to get a session - if database not initialized, this will raise RuntimeError
|
||||
async with get_db_session() as session:
|
||||
try:
|
||||
yield session
|
||||
# Auto-commit on successful completion
|
||||
await session.commit()
|
||||
except Exception:
|
||||
# Auto-rollback on error
|
||||
await session.rollback()
|
||||
raise
|
||||
except (ImportError, RuntimeError):
|
||||
# Database not available - yield None
|
||||
# Database not available or not initialized - yield None
|
||||
yield None
|
||||
return
|
||||
|
||||
# Use get_db_session context manager properly
|
||||
async with get_db_session() as session:
|
||||
try:
|
||||
yield session
|
||||
# Auto-commit on successful completion
|
||||
await session.commit()
|
||||
except Exception:
|
||||
# Auto-rollback on error
|
||||
await session.rollback()
|
||||
raise
|
||||
|
||||
|
||||
def get_current_user(
|
||||
|
||||
@@ -7,7 +7,6 @@ This module provides utilities for checking and validating media files
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional, Union
|
||||
|
||||
|
||||
# Standard media file names as defined by Kodi/Plex conventions
|
||||
POSTER_FILENAME = "poster.jpg"
|
||||
LOGO_FILENAME = "logo.png"
|
||||
|
||||
Reference in New Issue
Block a user