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

Criteria with is and another filter for the same field creates invalid query doucment #4850

Closed
fstorz opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@fstorz
Copy link

fstorz commented Dec 9, 2024

Description
When using the method is in the Criteria class together with any other filter element (without the and operator), then the created filter document is invalid.

Relevant code:

if (!NOT_SET.equals(isValue)) {
queryCriteria.put(this.key, this.isValue);
queryCriteria.putAll(document);
} else {

How to reproduce
The following Criteria object

Criteria.where("name")
    .is(123)
    .type(JsonSchemaObject.Type.INT_64)

creates

{"name": 123, "$type": ["long"]}

which is invalid.

Using the following Criteria object

Criteria.where("name")
    .in(123)
    .type(JsonSchemaObject.Type.INT_64)

creates

{"name": {"$in": [123], "$type": ["long"]}}

which is valid and more or less the same, just does not use "is".

Expected
When using is in combination with other filters for the same property, all filters should be combined into a sub-document using $eq for the equality check of the value provided to the is method.

Criteria.where("name")
    .is(123)
    .type(JsonSchemaObject.Type.INT_64)

should create

{"name": {"$eq": 123, "$type": ["long"]}}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 9, 2024
@christophstrobl
Copy link
Member

thanks for reporting, well look into this.

@christophstrobl christophstrobl self-assigned this Dec 10, 2024
mp911de pushed a commit that referenced this issue Jan 7, 2025
This commit wraps simple values and Patterns if to avoid creating invalid query objects.

Original pull request: #4862
Closes #4850
mp911de added a commit that referenced this issue Jan 7, 2025
Reduce test class and method visibility. Convert JUnit 4 test to JUnit 5. Reformat code.

Original pull request: #4862
See #4850
@mp911de mp911de closed this as completed in 91c6fcd Jan 7, 2025
mp911de added a commit that referenced this issue Jan 7, 2025
Reduce test class and method visibility. Convert JUnit 4 test to JUnit 5. Reformat code.

Original pull request: #4862
See #4850
mp911de pushed a commit that referenced this issue Jan 7, 2025
This commit wraps simple values and Patterns if to avoid creating invalid query objects.

Original pull request: #4862
Closes #4850
mp911de added a commit that referenced this issue Jan 7, 2025
Reduce test class and method visibility. Convert JUnit 4 test to JUnit 5. Reformat code.

Original pull request: #4862
See #4850
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 7, 2025
@mp911de mp911de added this to the 4.3.8 (2024.0.8) milestone Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants