Repository navigation
Fixes #31185: Return 400 for a pagination cursor the server did not issue - #39530
Conversation
…ssue
A list cursor that is valid base64 but not a JSON object of strings
(after=YWJj, [1,2], null, {"name":1}) failed with 500
JSON_PARSING_EXCEPTION, or later with a ClassCastException/NPE.
parseCursorMap now accepts only a JSON object of string or null values
and throws BadCursorException (400) otherwise. It also no longer NPEs on
a null cursor (Map.of with null values), which an empty before= reached.
The /history cursor had the same gap: a cursor without ':' threw a raw
RuntimeException, '123:' an ArrayIndexOutOfBoundsException and an empty
one an NPE. decodeAndValidateCursor now checks the <updatedAt>:<uuid>
shape the server issues and throws BadCursorException.
BaseEntityIT's cursor test accepted any exception, so a 500 passed it.
It now asserts 400 for every entity, for list and history cursors.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
There was a problem hiding this comment.
🟡 Changes recommended
An active, non-blocking finding in EntityRepository.java:3171 flags a return inside the try block that violates the repository’s single-return-at-end Java rule.
1 open issue
What changed in this PR
No blocking issues. This PR addresses the remaining pagination-cursor errors in #31185 by returning HTTP 400 instead of 500 for malformed list and history cursors.
Changes:
- Validates decoded cursor shapes and reports a consistent error.
- Adds parser unit tests and strengthens shared endpoint tests to require HTTP 400.
Placement: shared entity pagination used by REST and SDK clients; live CI and Collate were not independently verified.
Trade-off: none.
Recommendation: approve with non-blocking cleanup.
| File | Description |
|---|---|
| openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/EntityRepositoryCursorTest.java | Tests valid and malformed cursor parsing. |
| openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java | Validates cursor shapes and translates parsing failures. |
| openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/BaseEntityIT.java | Requires HTTP 400 for invalid cursors across entity endpoints. |
Review effort: Balanced
Code Review ✅ Approved 🟡 Medium riskChanging list and history cursor validation makes malformed cursors return 400 instead of 500, altering bounded API error handling for pagination clients. Fixes list and history pagination cursors that the server did not issue so they return 400 instead of 500, by validating the decoded cursor in VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |

Describe your changes:
Fixes #31185
A pagination cursor the server did not issue returned 500 instead of 400. Most of #31185 was already fixed by #36414 (FQN parsing), #35516 and #33655 (search); see this comment for the live re-check. This PR fixes what was left:
after/before, every entity):EntityRepository.parseCursorMapread the decoded cursor withJsonUtils.readValue(param, Map.class). A cursor that is valid base64 but not JSON (after=YWJj,[1,2]) threwJsonParsingException, which is hardcoded to 500.nulland{"name":1}got through and failed later with an NPE orClassCastException, which are also 500s. It now accepts only a JSON object of string or null values and throwsBadCursorException(400) for anything else. It also stops callingMap.ofwith null values on a null cursor (an NPE that an emptybefore=reached)./{entity}/history?after|before=):decodeAndValidateCursorthrew a rawRuntimeExceptionfor a cursor without:, anArrayIndexOutOfBoundsExceptionfor123:, and an NPE for an empty cursor. It now checks the<updatedAt>:<uuid>shape the server issues and throwsBadCursorException. The message is nowInvalid pagination cursorinstead ofCursor is not a valid cursor: <cursor>; no test or client depends on the old text.BaseEntityIT.get_entityListWithInvalidPaginationCursors_4xxassertedassertThrows(Exception.class, …), so a 500 passed. It now asserts 400 on every entity, for list and history cursors.Every cursor encoder that feeds
parseCursorMapwrites string values: the basegetCursorValue,TaskRepository,IngestionPipelineRepository,TestDefinitionRepository,ContextFileRepositoryandDistributedSearchIndexCoordinator. The stricter check therefore never rejects a cursor the server issued itself. The positive paging ITs below confirm this.Type of change:
High-level design:
N/A — small bug fix in two
EntityRepositorymethods.Tests:
Which test layer and why
EntityRepositoryCursorTest): both parsers are pure functions, so each malformed shape is checked directly.BaseEntityIT): the status code a client sees, on every entity's list and history endpoints.Use cases covered
GET /api/v1/<entity>?after=<base64 of abc | [1,2] | null | {"name":1}>, and the same withbefore, returns 400 on every entity (it was 500).GET /api/v1/<entity>?after=invalid-cursor-string(not base64) returns 400; this already worked and is now asserted as 400 instead of any exception.GET /api/v1/<entity>/history?after|before=<base64 of abc | 123:>returns 400 (it was 500).Unit tests
openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/EntityRepositoryCursorTest.java(18 tests). They failed before the fix for the right reasons:JsonParsingException, NPE,RuntimeException,ArrayIndexOutOfBoundsException, or no exception at all.EntityRepositoryCursorTest18/0,TagRepositoryUnitTest24/0,IngestionPipelineSortCursorTest12/0 (the existing callers ofparseCursorMap).EntityRepositoryCursorTest.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.BaseEntityIT.get_entityListWithInvalidPaginationCursors_4xx(accepted any exception) is replaced byget_entityListWithNonBase64Cursor_400,get_entityListWithInvalidPaginationCursors_400(4 cursors) andget_entityHistoryWithInvalidCursor_400(2 cursors × after/before).The merge queue is disabled, so these were run by hand rather than through
make java_affected_run; there is no generated results block.Full Java CI on this branch:
ci-merge-queue.ymlwithworkload=java, run 46828155562 on2ef46d322dd:backend-checks, k8s operator unit tests, image smoke testContainerResourceITandTestCaseResourceIT. Attempt 2 also had a MySQL deadlock inIndependentOntologyInverseIT.exportLinksThePairWithOwlInverseOf(ontology insert, unrelated to cursors)DataProductResourceIT.test_forgedDomainFqnCannotBypassTheDomainRule(expectsInvalidRequestException, getsOpenMetadataException). It fails the same way, at the same line and on all three engines, in themainnightly 46786795034 (df1fdcdc27e). It is not related to cursors.hung_test(exceeded its time budget). It is not a hang in this change:TestCaseResourceITstarted at 09:23:57 and was still making normal requests when the job was killed at 09:26:45. The 434 new cursor test cases took 18.3 s in total on that lane. The same lane also hit exit 124 onfix/audit-log-delete-time-and-search(run 46783217848), andmain's nightly finished it in 63 minutes. The classes it did not reach on MySQL all passed on both Postgres lanes.@Nestedhistory-paging tests (test_listEntityHistoryByTimestamp_pagination,_completePaginationCycle,_pagedWalkMatchesUnpaginatedRead) on 64 entity classes.Run locally (MySQL + Elasticsearch, parallel lane), before the push:
-Dit.test='*IT#get_entityListWith*Cursor*': 320/0 across 64 entity IT classes.-Dit.test='*IT#get_entityHistoryWithInvalidCursor_400': 128 run, 100 passed on 50 classes, 28 skipped (the 14 classes without a history endpoint), 0 failed.PaginationIT,IngestionPipelineSortIT,TaskResourceIT#testListPages*+testListEndpointSearchPagesBothWays,ContextFileIT#testListFilesOrderBy*and all ofPersonaResourceIT: 237 run, 0 failed.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
Against a local server built from
main(MySQL + Elasticsearch), before the fix:GET /api/v1/glossaries?limit=50&after=YWJj(base64 ofabc) →500 JSON_PARSING_EXCEPTION; the same forafter=WzEsMl0=, and on/glossaryTermsand/tables.GET /api/v1/glossaries?limit=50&after=not-base64!!→ 400 (already correct).After the fix, the same requests return 400 in the ITs above.
UI screen recording:
Not applicable — backend-only bug fix.
Checklist:
I have read CONTRIBUTING.md (the pre-review gate) and the contributor docs.
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 change.
For a UI feature or feature task: not applicable, backend-only.
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.Reviewed
2ef46d322ddwith a fresh-context reviewer: no 🔴 findings. One 🟡 left as is: an emptybefore=already returns 400, from the name check (unquoteName(null)), with the message "name must not be null" rather than "Invalid pagination cursor".Placement: any REST or SDK client that sends
after/beforeto an entity list or/history; the UI and ingestion only send back cursors the server issued.Trade-off: none. One JSON tree parse replaces one map parse, and a precompiled regex replaces the split-and-parse checks.
Recommendation: approve.
Decision check: no record needed. The cursor shape is an internal contract between
EntityRepository's own encoder and decoder; no other component or repo depends on it.Bug fix: I have added a test that covers the exact scenario we are fixing.
🤖 Generated with Claude Code