-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Raise IllegalArgumentException instead if query validation failed #26811
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
Conversation
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
|
@javanna it seems you were involved in the discuss on the relevant ticket. Care to take a look? |
javanna
left a comment
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.
Thanks a lot for your PR! I would have gone for IllegalArgumentException too, good choice. Adding a new exception has the disadvantage of needing to be supported by our serialization layer, which is a bit overkill in this case. Would you be up for adding a bit more test coverage? Some of the messages that you changed are not tested at all, it would be nice for instance to have a unit test for DefaultSearchContext and test the preProcess method if possible?
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.
I would also make the same change for "Cannot use [sort] option in conjunction with [rescore]." .
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.
we are not testing here the response code. Better to replace with catch: bad_request. That way we don't check the message, but we make sure that 400 is returned.
|
OK. Will do. Thanks for reviewing this PR. |
|
@javanna Please review again. |
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 one will start a node, which makes it more of an integration test, would it be possible to make it extend ESTestCase?
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.
Updated. Please review again.
|
@javanna Could you please review again? Thanks in advance. |
|
@elasticmachine test this please |
|
retest this please |
|
@javanna Seems like the testing is failed. Can I rebase this branch? |
|
@liketic feel free to rebase |
4ce89b4 to
f421d9a
Compare
|
@javanna Rebased. Please run test again. Thanks. |
|
retest this please |
|
@javanna I think the test failure is unrelated. Any thoughts? |
|
@liketic the last failure is related to your changes. What fails is a backwards compatibility test, which makes sense as your change is breaking backwards compatibility, although for a good cause. When running |
|
@liketic my bad, we should rather skip " - 6.99.99" as this change will go to master only (and will be released with 7.0). Would you also mind adding a note to the migrate guide ( |
|
retest this please |
|
@javanna Thanks for your patient. I updated the doc, any comments are appreciated. |
|
retest this please |
javanna
left a comment
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.
hi @liketic thanks for your changes, I left a couple more comments but this is very close!
| -------------------------------------------------- | ||
| // CONSOLE | ||
|
|
||
| === Scroll search will response `bad request` if request is invalid |
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.
I think we can skip the java exception names here given that this guide is read by all our users, also the ones that are not familiar with Java. Let's focus on response codes only. Also I would make the title shorter:
=== `_search/scroll` returns `400` for invalid requests
The `/_search/scroll` endpoint returns `400 - Bad request` when the request invalid, while it would previously return `500 - Internal Server Error` in such case.
| if (filters.size() > maxFilters){ | ||
| throw new QueryPhaseExecutionException(context, | ||
| throw new IllegalArgumentException( | ||
| "Number of filters is too large, must be less than or equal to: [" + maxFilters + "] but was [" |
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.
could we have a unit test for this change too?
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.
Yes.
|
|
||
| public class DefaultSearchContextTests extends ESTestCase { | ||
|
|
||
| public void testPreProcess() throws Exception { |
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.
thanks a lot for taking the time to write this!
| private void contextScrollKeepAlive(SearchContext context, long keepAlive) throws IOException { | ||
| if (keepAlive > maxKeepAlive) { | ||
| throw new QueryPhaseExecutionException(context, | ||
| throw new IllegalArgumentException( |
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.
do you think it would be possible to have a unit test for this too?
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.
It's not easy to add unit test for this. The SearchServiceTests is also extend ESSingleNodeTestCase for other test cases. And this has been covered by the integration test. I can try to add a unit test if you think it's necessary.
| } | ||
| AdjacencyMatrixAggregationBuilder builder = new AdjacencyMatrixAggregationBuilder("dummy", filters); | ||
| try { | ||
| builder.doBuild(context, null, new AggregatorFactories.Builder()); |
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.
can you use expectThrows here instead?
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.
my bad. Thanks.
| AggregatorFactory<?> factory = builder.doBuild(context, null, new AggregatorFactories.Builder()); | ||
| assertThat(factory instanceof AdjacencyMatrixAggregatorFactory, is(true)); | ||
| assertThat(factory.name(), equalTo("dummy")); | ||
| } |
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.
thanks a lot for adding this test!
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.
I did a last review round, this looks good, I left one minor remark but nothing blocking, I will merge once you made that minor change.
|
Hi @javanna , can we merge this now? Thanks! 😃 |
|
thanks @liketic merged to the master branch. |
* master: Enhances exists queries to reduce need for `_field_names` (elastic#26930) Added new terms_set query Set request body to required to reflect the code base (elastic#27188) Update Docker docs for 6.0.0-rc2 (elastic#27166) Add version 6.0.0 Docs: restore now fails if it encounters incompatible settings (elastic#26933) Convert index blocks to cluster block exceptions (elastic#27050) [DOCS] Link remote info API in Cross Cluster Search docs page Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125) [DOCS] Clarify migrate guide and search request validation Raise IllegalArgumentException if query validation failed (elastic#26811) prevent duplicate fields when mixing parent and root nested includes (elastic#27072) TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
* master: Remove checkpoint tracker bit sets setting Fix stable BWC branch detection logic Fix logic detecting unreleased versions Enhances exists queries to reduce need for `_field_names` (elastic#26930) Added new terms_set query Set request body to required to reflect the code base (elastic#27188) Update Docker docs for 6.0.0-rc2 (elastic#27166) Add version 6.0.0 Docs: restore now fails if it encounters incompatible settings (elastic#26933) Convert index blocks to cluster block exceptions (elastic#27050) [DOCS] Link remote info API in Cross Cluster Search docs page Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125) [DOCS] Clarify migrate guide and search request validation Raise IllegalArgumentException if query validation failed (elastic#26811) prevent duplicate fields when mixing parent and root nested includes (elastic#27072) TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
* master: Lazy initialize checkpoint tracker bit sets Remove checkpoint tracker bit sets setting Fix stable BWC branch detection logic Fix logic detecting unreleased versions Enhances exists queries to reduce need for `_field_names` (#26930) Added new terms_set query Set request body to required to reflect the code base (#27188) Update Docker docs for 6.0.0-rc2 (#27166) Add version 6.0.0 Docs: restore now fails if it encounters incompatible settings (#26933) Convert index blocks to cluster block exceptions (#27050) [DOCS] Link remote info API in Cross Cluster Search docs page Fix Laplace scorer to multiply by alpha (and not add) (#27125) [DOCS] Clarify migrate guide and search request validation Raise IllegalArgumentException if query validation failed (#26811) prevent duplicate fields when mixing parent and root nested includes (#27072) TopHitsAggregator must propagate calls to `setScorer`. (#27138)
|
I'm going to backport this to 6.x. I do not view this as |
Resolves #26799 . I'm trying to raise a
IllegalArgumentExceptionif the validation is failed. But I think it maybe not the best resolution, happy to hear your comments.