Skip to content
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

Ensure empty queries are returned as invalid (#33095) #33573

Closed
wants to merge 2 commits into from
Closed

Ensure empty queries are returned as invalid (#33095) #33573

wants to merge 2 commits into from

Conversation

cbismuth
Copy link
Contributor

@cbismuth cbismuth commented Sep 10, 2018

Null queries were causing an ActionRequestValidationException. To work around this issue, null queries are reset to a "match all" query which was already the default value.

Empty and whitespaces-only queries were already passing the test suite. Specific test cases have just been added to ensure that.

Null queries were causing an ActionRequestValidationException. To work
around this issue, null queries are reset to a "match all" query which
was already the default value.

Empty and whitespaces-only queries were already passing the test suite.
Specific test cases have just been added to ensure that.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

Copy link
Member

@javanna javanna left a 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 contribution @cbismuth ! I have reviewed it, left a couple of comments, and also realized that the original bug is not present anymore, so the PR is not really fixing it. That said I am not sure we should incorporate this fix given that it was submitted to fix an issue that is already fixed.

String index = "some_index";
createIndex(index, Settings.EMPTY);
QueryBuilder builder = QueryBuilders
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this test is not run anymore? It's fine to factor this code out but can you also leave the previous test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're totally right @javanna, I've probably made a bad cut/paste to get a test snippet, I'll restore the previous test.

@@ -1267,13 +1268,21 @@ public void testPutTemplateBadRequests() throws Exception {
assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]"));
}

public void testValidateQuery() throws IOException{
public void testValidateQueryWithNullQuery() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are ok but they always use a query builder and I suspect they don't exactly reproduce setting the query to null or empty. I think that we should also add a test that leverages the logic we have on the REST layer, see RestValidateQueryAction#prepareRequest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll add a such a test.

Copy link
Contributor Author

@cbismuth cbismuth Sep 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javanna, after reviewing my own commit, I now realize why we didn't understand each other. I've read the issue description far too fast, I though it was written: "an empty query should be marked as valid" ... my bad, sorry for all that noise, these are my first baby steps as an Elasticsearch contributor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries

@javanna javanna added :Search/Search Search-related issues that do not fall into other categories and removed :Core/Java High Level REST Client labels Sep 18, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@javanna
Copy link
Member

javanna commented Sep 18, 2018

One more thing, I am not sure how this change relates specifically to the high-level REST client, can you clarify that? Maybe I am missing something. Thanks!

@cbismuth
Copy link
Contributor Author

You're welcome @javanna.

I've added tests in the high-level REST client, that's why I've set this PR title. But your're right, the NPE check is in the server/action module.

I'll develop a cURL recreation script and use a debugger to have a better understanding of how validation works. Then, I'll check if a REST integration test has been developed and add a new one if none exists.

I'll let you know.

@cbismuth cbismuth changed the title Return "null" queries as "valid" to Rest High-Level Client (#33095) Ensure empty queries are returned as invalid (#33095) Sep 19, 2018
@cbismuth cbismuth closed this Sep 19, 2018
@cbismuth cbismuth deleted the 33095_validate_null_queries branch September 19, 2018 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants