Fix NFO 503 error on server reload with config fallback
- Add dynamic config loading in get_nfo_service() dependency - Handle settings reset during uvicorn reload in development - Add comprehensive tests for settings priority and fallback behavior - All 4 unit tests passing (settings priority, config fallback, error cases) - Update documentation with reload scenario fix
This commit is contained in:
@@ -45,14 +45,28 @@ async def get_nfo_service() -> NFOService:
|
||||
Raises:
|
||||
HTTPException: If NFO service not configured
|
||||
"""
|
||||
if not settings.tmdb_api_key:
|
||||
# Check if TMDB API key is in settings
|
||||
tmdb_api_key = settings.tmdb_api_key
|
||||
|
||||
# If not in settings, try to load from config.json
|
||||
if not tmdb_api_key:
|
||||
try:
|
||||
from src.server.services.config_service import get_config_service
|
||||
config_service = get_config_service()
|
||||
config = config_service.load_config()
|
||||
if config.nfo and config.nfo.tmdb_api_key:
|
||||
tmdb_api_key = config.nfo.tmdb_api_key
|
||||
except Exception:
|
||||
pass # Config loading failed, tmdb_api_key remains None
|
||||
|
||||
if not tmdb_api_key:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||
detail="NFO service not configured. TMDB API key required."
|
||||
)
|
||||
|
||||
return NFOService(
|
||||
tmdb_api_key=settings.tmdb_api_key,
|
||||
tmdb_api_key=tmdb_api_key,
|
||||
anime_directory=settings.anime_directory,
|
||||
image_size=settings.nfo_image_size,
|
||||
auto_create=settings.nfo_auto_create
|
||||
|
||||
Reference in New Issue
Block a user