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:
@@ -298,14 +298,14 @@ For each task completed:
|
|||||||
- **Fix**: ✅ Created `src/server/utils/media.py` utility module
|
- **Fix**: ✅ Created `src/server/utils/media.py` utility module
|
||||||
- **Status**: COMPLETED (January 24, 2026)
|
- **Status**: COMPLETED (January 24, 2026)
|
||||||
- **Resolution**:
|
- **Resolution**:
|
||||||
- Created comprehensive media utilities module with functions:
|
- Created comprehensive media utilities module with functions:
|
||||||
- `check_media_files()`: Check existence of standard media files
|
- `check_media_files()`: Check existence of standard media files
|
||||||
- `get_media_file_paths()`: Get paths to existing media files
|
- `get_media_file_paths()`: Get paths to existing media files
|
||||||
- `has_all_images()`: Check for complete image set
|
- `has_all_images()`: Check for complete image set
|
||||||
- `count_video_files()` / `has_video_files()`: Video file utilities
|
- `count_video_files()` / `has_video_files()`: Video file utilities
|
||||||
- Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS`
|
- Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS`
|
||||||
- Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py`
|
- Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py`
|
||||||
- Functions accept both `str` and `Path` for compatibility
|
- Functions accept both `str` and `Path` for compatibility
|
||||||
|
|
||||||
### Further Considerations (Require Architecture Decisions)
|
### Further Considerations (Require Architecture Decisions)
|
||||||
|
|
||||||
|
|||||||
@@ -165,22 +165,22 @@ async def get_optional_database_session() -> AsyncGenerator:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from src.server.database import get_db_session
|
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):
|
except (ImportError, RuntimeError):
|
||||||
# Database not available - yield None
|
# Database not available or not initialized - yield None
|
||||||
yield None
|
yield None
|
||||||
return
|
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(
|
def get_current_user(
|
||||||
credentials: Optional[HTTPAuthorizationCredentials] = Depends(
|
credentials: Optional[HTTPAuthorizationCredentials] = Depends(
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ This module provides utilities for checking and validating media files
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional, Union
|
from typing import Dict, Optional, Union
|
||||||
|
|
||||||
|
|
||||||
# Standard media file names as defined by Kodi/Plex conventions
|
# Standard media file names as defined by Kodi/Plex conventions
|
||||||
POSTER_FILENAME = "poster.jpg"
|
POSTER_FILENAME = "poster.jpg"
|
||||||
LOGO_FILENAME = "logo.png"
|
LOGO_FILENAME = "logo.png"
|
||||||
|
|||||||
Reference in New Issue
Block a user