Skip to content

Fixes 32491: return 404 from the incident-status by-id endpoints instead of a 500 - #32492

Merged
pmbrull merged 4 commits into
open-metadata:mainfrom
TeddyCr:fix-incident-status-get-404
Sep 5, 2026
Merged

pmbrull merged 4 commits into
open-metadata:mainfrom
TeddyCr:fix-incident-status-get-404

Conversation

@TeddyCr

@TeddyCr TeddyCr commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #32491

EntityTimeSeriesRepository.getById answers a missing row with null. Both the read and the patch handler on TestCaseResolutionStatusResource dereference that record to resolve the test case their authorization check is scoped to, so an id with no row threw a NullPointerException that the exception mapper rendered as a 500:

Cannot invoke "org.openmetadata.schema.tests.type.TestCaseResolutionStatus.getTestCaseReference()"
because "testCaseResolutionStatus" is null

The null is the record itself, not the reference — setInheritedFields is never reached, because getById returns at its jsonRecord == null guard.

The dereference arrived with #23448, which replaced the static authorize call with a data-driven one; before that the handler was return repository.getById(id); and a missing row was simply an empty body.

Callers reach it easily because two different ids are in play on this resource — the record id on /{id}, and the incident stateId on /stateId/{stateId}. TestCase.incidentId carries the stateId (TestCaseResolutionStatusRepository.getOngoingIncidentStateId returns latest.getStateId(), and TestCaseIndex stamps that into the incidentId search field), so a client that feeds incidentId to the by-id endpoint misses the record table every time. A stale incidentId left behind by a deleted incident does the same.

Both handlers now resolve the record through EntityTimeSeriesRepository.getByIdOrNotFound, and the operation documents its 404 so the generated spec matches.

The guard lives on the repository rather than in this resource because that is the layer producing the null, and it can build the message from its own entityType via CatalogExceptionMessage. It was otherwise going to be the third variant of the same check in the tree — EntityTimeSeriesRepository.patch throws inline with a hand-built message, AttachmentResource.getAssetById returns Response.status(NOT_FOUND). QueryCostResource.get had the identical unguarded dereference (repository.getById(...) then costRecord.getQueryReference().getId()) — visibly copied from this handler, down to the testCaseResolutionStatusId path-param name — so it now calls the same guard. Its path-param variable is renamed to id; the wire contract is unaffected because the @PathParam value was already "id".

getById keeps returning null — eight other resources call it and some callers depend on that, so the throwing variant is additive.

The repository's EntityTimeSeriesRepository.patch method deliberately keeps its own inline check rather than routing through getByIdOrNotFound: it reads the raw JSON and skips setInheritedFields, so going through getById would populate testCaseReference on the original and change what the patch diff sees. Same-looking guard, different contract.

To be unambiguous, since "patch" names two different things here: the PATCH handler on this resource is changed, and is covered by tests below. EntityTimeSeriesRepository.patch is not.

Type of change:

  • Bug fix

High-level design:

N/A — small change.

Tests:

Use cases covered

  • A caller requesting an incident-status id that has no row gets 404, not 500
  • A caller passing a stateId where a record id belongs (the production trigger, e.g. from TestCase.incidentId) gets 404
  • A caller requesting a real incident-status record still gets it back with its testCaseReference resolved
  • The same on GET /v1/queryCostRecord/{id}, which had the identical unguarded dereference

Unit tests

Not applicable — the change is a null guard on a JAX-RS handler whose behaviour is only observable as an HTTP status code, so it is covered by integration tests rather than a mocked unit test.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for the changed API endpoints.

  • Files updated: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/StaleIncidentStatusIT.java

    • byIdEndpointReturnsNotFoundForUnknownId
    • byIdEndpointReturnsNotFoundForStateId
    • byIdEndpointReturnsHealthyRecord
    • patchByIdReturnsNotFoundForUnknownId
    • patchByIdReturnsNotFoundForStateId
  • File added: openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/QueryCostRecordResourceIT.java

    • byIdEndpointReturnsNotFoundForUnknownId

The incident-status cases live in StaleIncidentStatusIT because it already covers stale incident state on the sibling stateId endpoint. Query cost gets its own file since none existed.

Red/green evidence. With the fix backed out and the tests unchanged:

Tests run: 3, Failures: 2, Errors: 0, Skipped: 0   # GET
byIdEndpointReturnsNotFoundForUnknownId
  ==> an id with no row must be a 404, not a NullPointerException: expected: <404> but was: <500>
byIdEndpointReturnsNotFoundForStateId
  ==> a stateId is not a record id, so it must 404: expected: <404> but was: <500>

byIdEndpointReturnsHealthyRecord passed in that run, so the two failures are the guard rather than the harness. With the fix restored:

The PATCH pair was red-checked the same way, by removing the guard from the PATCH handler alone:

Tests run: 2, Failures: 2, Errors: 0, Skipped: 0   # PATCH
patchByIdReturnsNotFoundForUnknownId  ==> expected: <404> but was: <500>
patchByIdReturnsNotFoundForStateId    ==> expected: <404> but was: <500>

With the guard in place:

Tests run: 10, Failures: 0, Errors: 0, Skipped: 0 -- StaleIncidentStatusIT
BUILD SUCCESS

The query-cost case was red-checked the same way — with the guard removed from that handler alone, expected: <404> but was: <500>.

Both classes together, with every guard in place:

Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

(11 = 5 pre-existing + 5 new incident-status + 1 new query-cost. Run with -DsearchType=opensearch.)

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Covered by the integration tests above, which drive the real endpoint through the SDK client against a testcontainers-backed stack (Postgres + OpenSearch) and assert on the HTTP status code — the same thing a manual curl would check.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: not applicable, no schema changes.
  • For UI changes: not applicable, no UI changes.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

Bug fix

  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

https://claude.ai/code/session_013D3LpP12bP6RBF2tFo5Rmn

…of a 500

EntityTimeSeriesRepository.getById answers a missing row with null. Both the
read and the patch handler on TestCaseResolutionStatusResource dereference that
record to resolve the test case their authorization check is scoped to, so an id
with no row threw a NullPointerException that the exception mapper rendered as a
500:

  Cannot invoke "TestCaseResolutionStatus.getTestCaseReference()"
  because "testCaseResolutionStatus" is null

The dereference arrived with open-metadata#23448, which replaced the static authorize call
with a data-driven one; before that the handler returned the null straight out
and a missing row was simply an empty body.

Two ids are in play on this resource: the record id on /{id} and the incident
stateId on /stateId/{stateId}. TestCase.incidentId carries the stateId, so any
client that feeds it to the by-id endpoint misses the record table every time
and takes the 500 rather than a 404 it could handle.

Resolve the record through one helper that throws EntityNotFoundException, and
document the 404 on the operation so the generated spec matches.

Leaves EntityTimeSeriesRepository.getById returning null: eight other resources
call it and some callers depend on the null.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013D3LpP12bP6RBF2tFo5Rmn
Copilot AI lite review requested due to automatic review settings September 2, 2026 15:57
@TeddyCr
TeddyCr requested a review from a team as a code owner September 2, 2026 15:57
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The behavioral fix is correct and covered by integration tests, with only a minor OpenAPI description-string nit noted in review comments.

Pull request overview

This PR fixes the /api/v1/dataQuality/testCases/testCaseIncidentStatus/{id} GET/PATCH behavior to return a proper 404 (via EntityNotFoundException) when the requested incident-status record ID has no corresponding time-series row, instead of throwing a NullPointerException that becomes a 500. It also adds integration coverage to ensure both “unknown id” and “stateId passed as id” scenarios return 404 while valid records still resolve testCaseReference.

Changes:

  • Introduced a shared helper to resolve a TestCaseResolutionStatus by id and throw EntityNotFoundException when missing (preventing NPE → 500).
  • Updated GET and PATCH handlers to use the helper before dereferencing testCaseReference.
  • Added integration tests validating 404 for unknown IDs / stateId misuse and 200 behavior for a valid record.
File summaries
File Description
openmetadata-service/src/main/java/org/openmetadata/service/resources/dqtests/TestCaseResolutionStatusResource.java Centralizes “get-or-404” resolution to prevent NPEs and updates GET/PATCH to use it; adds 404 response documentation for GET.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/StaleIncidentStatusIT.java Adds integration tests asserting 404 for missing/incorrect ids and validates a healthy record still returns with resolved testCaseReference.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The guard belongs in the layer that produces the null, not in one resource.
getByIdOrNotFound sits next to getById, builds its message from the repository's
own entityType through CatalogExceptionMessage, and is available to every
time-series resource that has to dereference the record it just read —
QueryCostResource.get has the same unguarded dereference today.

patch keeps its own inline check rather than routing through this. It reads the
raw JSON and deliberately skips setInheritedFields; going through getById would
populate testCaseReference on the original and change what the patch diff sees.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013D3LpP12bP6RBF2tFo5Rmn
Copilot AI review requested due to automatic review settings September 2, 2026 16:05
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The PATCH-by-id behavior was changed to return 404 as well, but there is currently no integration test asserting the PATCH endpoint returns 404 for missing ids/stateId-as-id, leaving the original regression vector partially unguarded.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

The PATCH handler resolves the record through the same getByIdOrNotFound guard,
so it regresses to the same 500 if that guard is dropped, but only GET was
asserted. Both new cases fail with 500 when the guard is removed from the
handler.

An empty patch is enough: the record is resolved, and the 404 thrown, before the
patch is applied.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013D3LpP12bP6RBF2tFo5Rmn
Copilot AI review requested due to automatic review settings September 2, 2026 16:33
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Sep 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, preserves existing getById semantics, and is backed by integration tests that reproduce and prevent the 500→404 regression on both GET and PATCH paths.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@TeddyCr
TeddyCr added this pull request to the merge queue Sep 2, 2026
@ShaileshParmar11
ShaileshParmar11 removed this pull request from the merge queue due to a manual request Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-03T08:30:04Z)

Blocked the queue: py-tests-status, py-tests-status

  • py-tests — py-tests-status, python / Verify Expected Jobs, python / Integration Tests (shard-2), python / Integration Tests (shard-2), python / Integration Tests (shard-2)
  • py-tests-postgres — py-tests-status, python / Verify Expected Jobs, python / Integration Tests (shard-2), python / Integration Tests (shard-2), python / Integration Tests (shard-2)

@pmbrull
pmbrull enabled auto-merge September 3, 2026 08:40
@pmbrull
pmbrull disabled auto-merge September 3, 2026 08:48
@pmbrull
pmbrull added this pull request to the merge queue Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — manual (2026-09-03T08:30:04Z)

Blocked the queue: py-tests-status, py-tests-status

  • py-tests — py-tests-status, python / Verify Expected Jobs, python / Integration Tests (shard-2), python / Integration Tests (shard-2), python / Integration Tests (shard-2)
  • py-tests-postgres — py-tests-status, python / Verify Expected Jobs, python / Integration Tests (shard-2), python / Integration Tests (shard-2), python / Integration Tests (shard-2)

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 3, 2026
@pmbrull
pmbrull added this pull request to the merge queue Sep 4, 2026
Merged via the queue into open-metadata:main with commit b052359 Sep 5, 2026
142 of 147 checks passed

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incident-status by-id endpoints 500 with a NullPointerException instead of returning 404

4 participants