Skip to content

Fixes #31185: Return 400 for a pagination cursor the server did not issue - #39530

Merged
yan-3005 merged 2 commits into
mainfrom
fix/31185-malformed-cursor-400
Dec 2, 2026
Merged

yan-3005 merged 2 commits into
mainfrom
fix/31185-malformed-cursor-400

Conversation

@yan-3005

@yan-3005 yan-3005 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • List cursors (after / before, every entity): EntityRepository.parseCursorMap read the decoded cursor with JsonUtils.readValue(param, Map.class). A cursor that is valid base64 but not JSON (after=YWJj, [1,2]) threw JsonParsingException, which is hardcoded to 500. null and {"name":1} got through and failed later with an NPE or ClassCastException, which are also 500s. It now accepts only a JSON object of string or null values and throws BadCursorException (400) for anything else. It also stops calling Map.of with null values on a null cursor (an NPE that an empty before= reached).
  • History cursors (/{entity}/history?after|before=): decodeAndValidateCursor threw a raw RuntimeException for a cursor without :, an ArrayIndexOutOfBoundsException for 123:, and an NPE for an empty cursor. It now checks the <updatedAt>:<uuid> shape the server issues and throws BadCursorException. The message is now Invalid pagination cursor instead of Cursor is not a valid cursor: <cursor>; no test or client depends on the old text.
  • Why it went unnoticed: BaseEntityIT.get_entityListWithInvalidPaginationCursors_4xx asserted assertThrows(Exception.class, …), so a 500 passed. It now asserts 400 on every entity, for list and history cursors.

Every cursor encoder that feeds parseCursorMap writes string values: the base getCursorValue, TaskRepository, IngestionPipelineRepository, TestDefinitionRepository, ContextFileRepository and DistributedSearchIndexCoordinator. The stricter check therefore never rejects a cursor the server issued itself. The positive paging ITs below confirm this.

Type of change:

  • Bug fix

High-level design:

N/A — small bug fix in two EntityRepository methods.

Tests:

Which test layer and why

  • Unit (EntityRepositoryCursorTest): both parsers are pure functions, so each malformed shape is checked directly.
  • Java IT (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 with before, 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).
  • Server-issued list and history cursors still page forward and backward.

Unit tests

  • I added unit tests for the new/changed logic.
  • Added: 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.
  • After the fix: EntityRepositoryCursorTest 18/0, TagRepositoryUnitTest 24/0, IngestionPipelineSortCursorTest 12/0 (the existing callers of parseCursorMap).
  • Coverage: not measured with JaCoCo. Every changed line and branch is exercised by EntityRepositoryCursorTest.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Updated: BaseEntityIT. get_entityListWithInvalidPaginationCursors_4xx (accepted any exception) is replaced by get_entityListWithNonBase64Cursor_400, get_entityListWithInvalidPaginationCursors_400 (4 cursors) and get_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.yml with workload=java, run 46828155562 on 2ef46d322dd:

Lane Result
backend-checks, k8s operator unit tests, image smoke test passed
global-state, multi-node, rdf, retry-queue (all three engines) passed
parallel, postgres-opensearch 21,401 tests, 1 failure (pre-existing, below)
parallel, postgres-elasticsearch-redis 21,199 tests, 1 failure (pre-existing, below)
parallel, mysql-elasticsearch 20,254 tests, 1 failure (pre-existing). Hit the job time limit (exit 124) on both attempts, with ~73 classes still queued, including ContainerResourceIT and TestCaseResourceIT. Attempt 2 also had a MySQL deadlock in IndependentOntologyInverseIT.exportLinksThePairWithOwlInverseOf (ontology insert, unrelated to cursors)
  • The only failure is DataProductResourceIT.test_forgedDomainFqnCannotBypassTheDomainRule (expects InvalidRequestException, gets OpenMetadataException). It fails the same way, at the same line and on all three engines, in the main nightly 46786795034 (df1fdcdc27e). It is not related to cursors.
  • MySQL lane timeout: CI classified it hung_test (exceeded its time budget). It is not a hang in this change: TestCaseResourceIT started 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 on fix/audit-log-delete-time-and-search (run 46783217848), and main's nightly finished it in 63 minutes. The classes it did not reach on MySQL all passed on both Postgres lanes.
  • Every cursor and paging test passed on all three engines (from the uploaded failsafe reports), including the @Nested history-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.
  • Positive paging with server-issued cursors: PaginationIT, IngestionPipelineSortIT, TaskResourceIT#testListPages*+testListEndpointSearchPagesBothWays, ContextFileIT#testListFilesOrderBy* and all of PersonaResourceIT: 237 run, 0 failed.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Against a local server built from main (MySQL + Elasticsearch), before the fix:

  1. GET /api/v1/glossaries?limit=50&after=YWJj (base64 of abc) → 500 JSON_PARSING_EXCEPTION; the same for after=WzEsMl0=, and on /glossaryTerms and /tables.
  2. 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 (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    Reviewed 2ef46d322dd with a fresh-context reviewer: no 🔴 findings. One 🟡 left as is: an empty before= 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/before to 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

…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.
@yan-3005
yan-3005 marked this pull request as ready for review December 2, 2026 10:03
@yan-3005
yan-3005 requested a review from a team as a code owner December 2, 2026 10:03
@yan-3005
yan-3005 requested review from mohityadav766 and a balanced review from Copilot and removed request for a team December 2, 2026 10:04
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This 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 skip-pr-checks label.

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

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

Copilot AI balanced review requested due to automatic review settings December 2, 2026 10:59

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@gitar-bot

gitar-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Changing 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 EntityRepository.parseCursorMap and decodeAndValidateCursor and throwing BadCursorException. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@yan-3005
yan-3005 merged commit 2a8eb98 into main Dec 2, 2026
24 of 25 checks passed
@yan-3005
yan-3005 deleted the fix/31185-malformed-cursor-400 branch December 2, 2026 11:25
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.

Return 4xx for unparseable FQNs and cursors so one legacy glossary row can't 500 an entire page

4 participants