From 456cee8ca08e825fc29dbb83c30bbe7e6a60b219 Mon Sep 17 00:00:00 2001 From: hunterxtang <38674961+hunterxtang@users.noreply.github.com> Date: Thu, 2 Jul 2026 12:11:22 -0700 Subject: [PATCH 1/3] fix: preserve HTTPException status in update_docling_preset (#1586) --- src/api/settings/endpoints.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.py index b672161c2..d8139ebb0 100644 --- a/src/api/settings/endpoints.py +++ b/src/api/settings/endpoints.py @@ -1601,7 +1601,9 @@ async def update_docling_preset( settings=settings_toggles, preset_config=preset_config, ) - + except HTTPException: + # Preserve intended HTTP status codes (e.g. 400 for an invalid preset) + raise except Exception as e: logger.error("Failed to update docling settings", error=str(e)) raise HTTPException( From fe14df77459c2bd8df4fea3c48f123ad9a7bc69d Mon Sep 17 00:00:00 2001 From: hunterxtang <38674961+hunterxtang@users.noreply.github.com> Date: Thu, 2 Jul 2026 12:12:33 -0700 Subject: [PATCH 2/3] fix: drop raw exception from docling-preset 500 detail and add 400 regression test (#1586) --- src/api/settings/endpoints.py | 2 +- tests/unit/api/test_settings_endpoints.py | 37 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/unit/api/test_settings_endpoints.py diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.py index d8139ebb0..97d749d4b 100644 --- a/src/api/settings/endpoints.py +++ b/src/api/settings/endpoints.py @@ -1607,7 +1607,7 @@ async def update_docling_preset( except Exception as e: logger.error("Failed to update docling settings", error=str(e)) raise HTTPException( - status_code=500, detail=f"Failed to update docling settings: {str(e)}" + status_code=500, detail="Failed to update docling settings" ) from e diff --git a/tests/unit/api/test_settings_endpoints.py b/tests/unit/api/test_settings_endpoints.py new file mode 100644 index 000000000..88177acb5 --- /dev/null +++ b/tests/unit/api/test_settings_endpoints.py @@ -0,0 +1,37 @@ +""" +Unit tests for api.settings.endpoints +Validates error handling in update_docling_preset endpoint. +""" + +from unittest.mock import AsyncMock, MagicMock + +import pytest +from fastapi import HTTPException + +from api.settings import DoclingPresetBody, update_docling_preset +from session_manager import User + + +@pytest.mark.asyncio +async def test_update_docling_preset_invalid_preset_returns_400(): + """Test that an invalid preset value returns 400 status code. + + This test ensures that the HTTPException with status_code=400 raised + for invalid presets is not masked by the broad Exception handler. + Regression test for issue #1586. + """ + # Create a body with an invalid preset + body = DoclingPresetBody(preset="nonexistent_preset") + + # Mock dependencies + session_manager = AsyncMock() + user = MagicMock(spec=User) + + # Call the endpoint and expect HTTPException with 400 + with pytest.raises(HTTPException) as exc_info: + await update_docling_preset(body=body, session_manager=session_manager, user=user) + + # Assert it's a 400 error (not 500) + assert exc_info.value.status_code == 400 + assert "Invalid preset" in exc_info.value.detail + assert "nonexistent_preset" in exc_info.value.detail From 40334e121dea2aa3bbb61cf73723866c2063d73f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 19:15:10 +0000 Subject: [PATCH 3/3] style: ruff autofix (auto) --- src/api/settings/endpoints.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.py index 97d749d4b..7defe344a 100644 --- a/src/api/settings/endpoints.py +++ b/src/api/settings/endpoints.py @@ -1606,9 +1606,7 @@ async def update_docling_preset( raise except Exception as e: logger.error("Failed to update docling settings", error=str(e)) - raise HTTPException( - status_code=500, detail="Failed to update docling settings" - ) from e + raise HTTPException(status_code=500, detail="Failed to update docling settings") from e async def refresh_openrag_docs(