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:
@@ -165,12 +165,8 @@ 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
|
||||||
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:
|
async with get_db_session() as session:
|
||||||
try:
|
try:
|
||||||
yield session
|
yield session
|
||||||
@@ -180,6 +176,10 @@ async def get_optional_database_session() -> AsyncGenerator:
|
|||||||
# Auto-rollback on error
|
# Auto-rollback on error
|
||||||
await session.rollback()
|
await session.rollback()
|
||||||
raise
|
raise
|
||||||
|
except (ImportError, RuntimeError):
|
||||||
|
# Database not available or not initialized - yield None
|
||||||
|
yield None
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_current_user(
|
def get_current_user(
|
||||||
|
|||||||
@@ -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