diff --git a/keep/api/routes/incidents.py b/keep/api/routes/incidents.py index 87438a5fe9..35042554e8 100644 --- a/keep/api/routes/incidents.py +++ b/keep/api/routes/incidents.py @@ -527,7 +527,10 @@ def merge_incidents( if failed_ids: message += f", {pluralize(len(failed_ids), 'incident')} failed to merge" - raise HTTPException(f"Some incidents failed to merge. {message}") + raise HTTPException( + status_code=500, + detail=f"Some incidents failed to merge. {message}", + ) return MergeIncidentsResponseDto( merged_incident_ids=merged_ids, diff --git a/tests/test_incidents.py b/tests/test_incidents.py index 66f0faed9a..96b4b7b1cf 100644 --- a/tests/test_incidents.py +++ b/tests/test_incidents.py @@ -907,6 +907,28 @@ def test_merge_incidents_app( """ +@pytest.mark.parametrize("test_app", ["NO_AUTH"], indirect=True) +def test_merge_incidents_app_reports_partial_failure(client, test_app): + source_id = uuid4() + destination_id = uuid4() + + with patch( + "keep.api.routes.incidents.merge_incidents_to_id", + return_value=([], [source_id]), + ): + response = client.post( + "/incidents/merge", + headers={"x-api-key": "some-key"}, + json={ + "source_incident_ids": [str(source_id)], + "destination_incident_id": str(destination_id), + }, + ) + + assert response.status_code == 500 + assert "failed to merge" in response.json()["detail"] + + @pytest.mark.asyncio async def test_split_incident(db_session, create_alert): # Create source incident with multiple alerts