Repository navigation
Fixes 32491: return 404 from the incident-status by-id endpoints instead of a 500 - #32492
Conversation
…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
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
There was a problem hiding this comment.
🟢 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
TestCaseResolutionStatusby id and throwEntityNotFoundExceptionwhen 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
There was a problem hiding this comment.
🟡 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
There was a problem hiding this comment.
🟢 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
|
🚦 Removed from the merge queue —
|
🚦 Removed from the merge queue —
|
b052359



Describe your changes:
Fixes #32491
EntityTimeSeriesRepository.getByIdanswers a missing row withnull. Both the read and the patch handler onTestCaseResolutionStatusResourcedereference that record to resolve the test case their authorization check is scoped to, so an id with no row threw aNullPointerExceptionthat the exception mapper rendered as a 500:The null is the record itself, not the reference —
setInheritedFieldsis never reached, becausegetByIdreturns at itsjsonRecord == nullguard.The dereference arrived with #23448, which replaced the static
authorizecall with a data-driven one; before that the handler wasreturn 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 incidentstateIdon/stateId/{stateId}.TestCase.incidentIdcarries the stateId (TestCaseResolutionStatusRepository.getOngoingIncidentStateIdreturnslatest.getStateId(), andTestCaseIndexstamps that into theincidentIdsearch field), so a client that feedsincidentIdto the by-id endpoint misses the record table every time. A staleincidentIdleft 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 ownentityTypeviaCatalogExceptionMessage. It was otherwise going to be the third variant of the same check in the tree —EntityTimeSeriesRepository.patchthrows inline with a hand-built message,AttachmentResource.getAssetByIdreturnsResponse.status(NOT_FOUND).QueryCostResource.gethad the identical unguarded dereference (repository.getById(...)thencostRecord.getQueryReference().getId()) — visibly copied from this handler, down to thetestCaseResolutionStatusIdpath-param name — so it now calls the same guard. Its path-param variable is renamed toid; the wire contract is unaffected because the@PathParamvalue was already"id".getByIdkeeps returningnull— eight other resources call it and some callers depend on that, so the throwing variant is additive.The repository's
EntityTimeSeriesRepository.patchmethod deliberately keeps its own inline check rather than routing throughgetByIdOrNotFound: it reads the raw JSON and skipssetInheritedFields, so going throughgetByIdwould populatetestCaseReferenceon 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.patchis not.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
stateIdwhere a record id belongs (the production trigger, e.g. fromTestCase.incidentId) gets 404testCaseReferenceresolvedGET /v1/queryCostRecord/{id}, which had the identical unguarded dereferenceUnit 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.javabyIdEndpointReturnsNotFoundForUnknownIdbyIdEndpointReturnsNotFoundForStateIdbyIdEndpointReturnsHealthyRecordpatchByIdReturnsNotFoundForUnknownIdpatchByIdReturnsNotFoundForStateIdFile added:
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/QueryCostRecordResourceIT.javabyIdEndpointReturnsNotFoundForUnknownIdThe incident-status cases live in
StaleIncidentStatusITbecause it already covers stale incident state on the siblingstateIdendpoint. Query cost gets its own file since none existed.Red/green evidence. With the fix backed out and the tests unchanged:
byIdEndpointReturnsHealthyRecordpassed 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:
With the guard in place:
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:
(11 = 5 pre-existing + 5 new incident-status + 1 new query-cost. Run with
-DsearchType=opensearch.)Ingestion integration tests
Playwright (UI) tests
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
curlwould check.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.Bug fix
🤖 Generated with Claude Code
https://claude.ai/code/session_013D3LpP12bP6RBF2tFo5Rmn