Skip to content

fix(incidents): return a valid error when some incidents fail to merge - #6965

Open
nazarli-shabnam wants to merge 1 commit into
keephq:mainfrom
nazarli-shabnam:fix/5173-merge-incidents-error-response
Open

nazarli-shabnam wants to merge 1 commit into
keephq:mainfrom
nazarli-shabnam:fix/5173-merge-incidents-error-response

Conversation

@nazarli-shabnam

@nazarli-shabnam nazarli-shabnam commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5173

Problem

When some incidents fail to merge, POST /incidents/merge runs raise HTTPException(f"Some incidents failed to merge. {message}"). The first argument of HTTPException is status_code, so the message is used as a status code and Starlette fails with 'Some incidents failed to merge. ...' is not a valid HTTPStatus. The client gets a broken response instead of the error, which fits the "unexpected end of JSON input" in #5173.

Fix

Pass status_code=500 and the message as detail.

This does not explain why a merge of three or more incidents fails in the first place. merge_incidents_to_id loops over every source incident, so I could not find the original cause by reading the code; this PR only makes the failure report correctly. The linked-issue check requires a closing keyword, so this PR says Closes; if you want the issue to stay open until the cause of the failed merges is found, please reopen it.

Tests

Added test_merge_incidents_app_reports_partial_failure in tests/test_incidents.py. It patches merge_incidents_to_id to report one failed incident and expects a 500 with the message in detail.

Run in a throwaway python:3.12 container after poetry install --no-root --with dev. Before the fix it failed with ValueError: ... is not a valid HTTPStatus; after the fix it passed.

Not verified

  • I only ran this one test, not the rest of tests/test_incidents.py. The existing test_merge_incidents_app is inside a string literal in that file (disabled), so nothing else covers this route.
  • 500 is my choice of status for a partial failure; say if you prefer another.
  • I did not run black or isort. I wrapped the line by hand.

AI disclosure

Claude (Anthropic) helped investigate the bug and draft the change and this description. I reviewed the diff.

The merge route raised HTTPException with the message as its first argument, which is status_code, so FastAPI failed with 'is not a valid HTTPStatus' and the client got a broken response instead of the list of failures. Pass status_code=500 and the message as detail.

Related to keephq#5173

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Can't merge more than 2 Incidents

1 participant