Repository navigation
Fixes #35037: Reject negative search pagination before it reaches the search engine #35039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...a-service/src/test/java/org/openmetadata/service/resources/search/SearchResourceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package org.openmetadata.service.resources.search; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.mockStatic; | ||
| import static org.mockito.Mockito.verifyNoInteractions; | ||
|
|
||
| import jakarta.ws.rs.BadRequestException; | ||
| import jakarta.ws.rs.core.SecurityContext; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.CsvSource; | ||
| import org.mockito.MockedStatic; | ||
| import org.openmetadata.schema.search.PreviewSearchRequest; | ||
| import org.openmetadata.service.Entity; | ||
| import org.openmetadata.service.search.SearchRepository; | ||
| import org.openmetadata.service.security.Authorizer; | ||
|
|
||
| class SearchResourceTest { | ||
|
|
||
| @ParameterizedTest | ||
| @CsvSource({"-25, 25, from", "0, -1, size", ", -1, size"}) | ||
| void previewSearchRejectsNegativePaginationWithoutSearching( | ||
| Integer from, Integer size, String rejectedField) { | ||
| SearchRepository searchRepository = mock(SearchRepository.class); | ||
| try (MockedStatic<Entity> entity = mockStatic(Entity.class)) { | ||
| entity.when(Entity::getSearchRepository).thenReturn(searchRepository); | ||
| SearchResource resource = new SearchResource(mock(Authorizer.class)); | ||
| PreviewSearchRequest request = | ||
| new PreviewSearchRequest() | ||
| .withQuery("*") | ||
| .withIndex("table") | ||
| .withFrom(from) | ||
| .withSize(size); | ||
|
|
||
| BadRequestException error = | ||
| assertThrows( | ||
| BadRequestException.class, | ||
| () -> resource.previewSearch(mock(SecurityContext.class), request)); | ||
|
|
||
| assertEquals(rejectedField + " must be greater than or equal to 0", error.getMessage()); | ||
| verifyNoInteractions(searchRepository); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR sets a new API contract for
/v1/search/query,/nlq/query,/fieldQueryand/preview: a negativefrom/sizeis 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/exportand/export/asyncdeliberately keep ignoringfrom <= 0. Neither rule is written down anywhere in the tree, and nothing indocs/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 negativefromorsizewith 400 at the resource boundary and never clamp it to 0, andsize=0stays valid for count-only queries. The export endpoints are the exception: they ignorefrom <= 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:
Was this helpful? React with 👍 / 👎