Repository navigation
Fixes #35037: Reject negative search pagination before it reaches the search engine - #35039
Conversation
… engine /v1/search/query, /v1/search/nlq/query and /v1/search/fieldQuery handed from/size to Elasticsearch/OpenSearch unchecked, so a negative value was only caught by the engine: a 500 with a server-side stack trace on 2.0.x, and still a 500 on main for the NLQ and field-query endpoints. Bound both parameters with @min(0) so Jersey answers 400 before the resource runs (no cache lookup, no engine call), and check the /v1/search/preview request body the same way. Negative values are rejected rather than clamped, so a caller's paging bug stays visible instead of quietly serving page 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
| @Collection(name = "search") | ||
| @LatencyPhase | ||
| public class SearchResource { | ||
| private static final String MUST_BE_NON_NEGATIVE = "must be greater than or equal to 0"; |
There was a problem hiding this comment.
⚠️ Quality: Reject-not-clamp pagination rule lives only in the PR description
This PR sets a new API contract for /v1/search/query, /nlq/query, /fieldQuery and /preview: a negative from/size is now rejected with a 400. Clients and the UI have to agree with that contract, which makes it a decision-record trigger. The reasoning is only in the description: "Negative values are rejected, not clamped to 0. Clamping would hide the caller's paging bug and serve page 1 to a client that asked for page 0." The description also says /v1/search/export and /export/async deliberately keep ignoring from <= 0. Neither rule is written down anywhere in the tree, and nothing in docs/decisions/ covers search pagination. The repo squash-merges, so the next contributor can't see why. They could "helpfully" clamp instead, or make export consistent and break it, and nothing in the tree would stop them. Per ADR:2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body, add a record. Suggested wording: "Search endpoints that paginate reject a negative from or size with 400 at the resource boundary and never clamp it to 0, and size=0 stays valid for count-only queries. The export endpoints are the exception: they ignore from <= 0." If you think no lasting rule survives this change, say so and this can be closed.
Add a decision record stating the pagination rule:
# docs/decisions/2026-10-xx-search-pagination-rejects-negative-values.md
- **Status:** Accepted
## Decision
Search endpoints that paginate (`/v1/search/query`, `/nlq/query`, `/fieldQuery`, `/preview`)
reject a negative `from` or `size` with 400 before the cache or engine is touched; they never
clamp to 0, because clamping hides the caller's paging bug. `size=0` stays valid (count-only).
`/v1/search/export*` ignore `from <= 0`.
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
|
…ta#35040) Clamp zero and negative page numbers in regular and natural-language UI searches to the first page, preserving valid pagination and count-only requests. Add Jest regression coverage for the request offsets and a Playwright regression for a Queries-tab URL with queryFrom=0&pageSize=25. Refs open-metadata#35037. Backend request validation is handled separately in open-metadata#35039.
…ted failures logged as errors [2.0] (#35302) * Fixes #35037: reject negative search pagination before it reaches the engine [2.0] Backport of #35039 and #35040. A negative from or size on the search endpoints is rejected with a 400 that names the parameter instead of failing in the search engine as a 500, and the UI no longer sends a negative offset. SearchResourceIT conflicted: 2.0 has neither the httpGetSearch helper nor the 400 mapping the old negative-offset test expected, so the new tests and helpers were added by hand. (cherry picked from commit 893cd1b) (cherry picked from commit e3914c5) * Fixes #35293: serve glossary CSV documentation for glossary-term import [2.0] The bulk import page asks /v1/csv/documentation/{entityType} for the type it imports into. For a glossary term that is glossaryTerm, which has no documentation file, so every request returned a 500 and was logged twice at ERROR. Glossary-term import already goes through GlossaryCsv, so glossaryTerm now gets the glossary's documentation. A type with no documentation returns a 404, and the FATAL log before the rethrow is gone. * Apply a workflow approval when the approver is not a reviewer [2.0] Anyone the task policy lets resolve an approval task, such as an admin or an owner, could approve a glossary term without being one of its reviewers. The workflow then set the status as that user, the reviewer check rejected it, and the failure was only logged: the task closed as Approved while the term stayed In Review. As on main since #34541, a status change the governance workflow makes, as or impersonating governance-bot, skips the reviewer check: the approval task already decided who may approve. Direct edits are still checked. SetGlossaryTermStatusImpl now writes impersonating governance-bot like the other workflow nodes, so its changes are recognised too. * Skip deleted alert recipients without logging an error [2.0] An alert can name a user or team that is deleted later. Every event for that alert logged the lookup failure at ERROR with a stack trace, although there is simply no one left to notify. A missing recipient is now skipped at DEBUG, as main does since #33967; any other lookup failure is still logged as an error. * Mock the 2.0 API client in the backported pagination test The pagination tests from #35040 mock ./axiosClient, which only exists on main. On 2.0 searchAPI imports its client from ./index, so the mock could not resolve and all 12 new cases failed. Mock ./index like the rest of the file. * Verify the impersonated status patch in BatchModeNodesTest #35239 brought this test to 2.0 while this branch made SetGlossaryTermStatusImpl patch impersonating governance-bot, so the test still expected the plain four-argument patch. It now checks the same call main's copy of the test does.



Describe your changes:
Fixes #35037
/v1/search/query,/v1/search/nlq/queryand/v1/search/fieldQuerypassedfromandsizeto Elasticsearch/OpenSearch without checking them. A negative value, such asfrom=-25&size=25(seen in the field), was only rejected by the engine:main, Fixes #27990: stop malformed search input failing as a server error #33655 already turns the/v1/search/querycase into a 400, but the request still makes a round trip to the engine.main, the NLQ and field-query endpoints still return 500.Changes:
SearchResource:fromandsizeon those three endpoints now carry@Min(0), aslimit/offsetalready do in other resources. Jersey rejects the request before the resource method runs, so neither the response cache nor the engine is touched. The response is400 [query param from must be greater than or equal to 0]./v1/search/preview: the request body'sfrom/sizeare checked explicitly, returning400 from must be greater than or equal to 0. I didn't add@Validto the body, because it would also start validating the whole nestedSearchSettings./v1/search/exportand/v1/search/export/asyncare unchanged, because they already ignorefrom <= 0.Type of change:
High-level design:
N/A — small change.
Tests:
Use cases covered
GET /v1/search/query?from=-25&size=25returns 400 namingfrom, without querying the engine.sizeon/v1/search/queryfromon/v1/search/nlq/queryfromorsizeon/v1/search/fieldQueryfromorsizein the/v1/search/previewbody returns 400. Afromsent asnullis still treated as absent.size=0for count-only queries.Unit tests
openmetadata-service/src/test/java/org/openmetadata/service/resources/search/SearchResourceTest.java(new). It checks that the preview guard rejects a negativefromorsizewithout callingSearchRepository.SearchResourceTestonly, on the lines this PR changes inSearchResource:sizecheck call. The test does execute it, but JaCoCo doesn't count a line whose call exits by throwing.@Minannotations have no executable lines; the ITs below cover them.plan_local_java_tests.pyalso selectsSearchRepositoryBehaviorTest(142/142) andSearchStatsResourceTest(9/9). Both pass.Backend integration tests
openmetadata-integration-tests/for new/changed API endpoints.openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/SearchResourceIT.javatestSearchWithNegativeOffsetnow asserts the boundary message. It used to pass on any error, including the engine's own rejection.testNegativePaginationIsRejectedAsBadRequest(4 cases) andtestPreviewSearchWithNegativeOffsetIsRejectedAsBadRequest.mainatf0d254f6fe:-Pmysql-elasticsearch, fullSearchResourceIT: 82 run, 0 failures. 3 skipped, all existing@Disabledsuggest tests.-Pmysql-opensearch, the new tests plus the SearchException: Search failed due to Request failed: [search_phase_execution_exception] all shards failed | Root cause: [parse_exception: parse_exception: Encountered " ":" ": "" at line 1, column 0. #27990 tests: 15/15 pass.SearchResourcechange reverted, all 6 new or updated tests fail./queryreturns 400 with the engine's message;/nlq/query,/fieldQueryand/previewreturn 500.plan_local_java_tests.pyalso selects 72 other search-area and smoke IT classes, which I did not run locally. No other test sends a negativefrom/size.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
parameter cannot be negativeengine error, so the engine was never queried.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.🤖 Generated with Claude Code