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:
2026-01-24 21:39:31 +01:00
parent 46271a9845
commit 8647da8474
3 changed files with 21 additions and 22 deletions

View File

@@ -165,12 +165,8 @@ async def get_optional_database_session() -> AsyncGenerator:
"""
try:
from src.server.database import get_db_session
except (ImportError, RuntimeError):
# Database not available - yield None
yield None
return
# Use get_db_session context manager properly
# Try to get a session - if database not initialized, this will raise RuntimeError
async with get_db_session() as session:
try:
yield session
@@ -180,6 +176,10 @@ async def get_optional_database_session() -> AsyncGenerator:
# Auto-rollback on error
await session.rollback()
raise
except (ImportError, RuntimeError):
# Database not available or not initialized - yield None
yield None
return
def get_current_user(

View File

@@ -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"