Skip to content

Throw UnsupportedOperationException for dynamic queries with unsupported keywords #2099

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

Closed
Thunderforge opened this issue Jun 24, 2021 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@Thunderforge
Copy link

Thunderforge commented Jun 24, 2021

Consider #2080, which added support for the OrderBy keyword in dynamic queries. For example, your repository can call findAllOrderByBar() and it will return all elements sorted by the bar field.

Before this change, if your repository had findAllOrderByBar(), the method gets called and nothing is sorted. This is definitely a surprise for the user. Similarly, if the user tries to use other keywords they might expect (perhaps findByAgeLessThan(int age), Spring Redis will return data that doesn't match the user's expectations.

I would like to suggest that for situations like this with unsupported keywords, an UnsupportedOperationException is thrown (or another exception if it is more appropriate). Perhaps more generally if there is anything about the method name that isn't understood (like if field bar doesn't exist or isn't @Indexed), an exception could be thrown as well.

This would save developers time debugging code that appears to be valid, but will never work.

Current Behavior

Calling a dynamic query with an unsupported keyword does not return data that the developer expects.

Desired behavior

Calling a dynamic query with an unsupported keyword should throw an UnsupportedOperationException or a similarly appropriate exception.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 24, 2021
@mp911de
Copy link
Member

mp911de commented Jun 25, 2021

Actually, this is already in place. The missing bit in #2080 was the missing invocation of sorting.

The relationship between @Indexed and a derived query using such property is a bit more tricky as indexing can happen also outside of Spring Data Redis so we do not have a way to know about that. Generally, starting with tests to ensure proper usage is a good approach.

Is there anything actionable on this ticket left?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Jun 25, 2021
@Thunderforge
Copy link
Author

So the issue in #2080 was that the OrderBy keyword was supported, but not working properly?

In that case, I may have overgeneralized the situation. If there are technical hurdles with @Indexed, then I do not think there is anything actionable to do with this ticket.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 29, 2021
@mp911de mp911de added status: invalid An issue that we don't feel is valid and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jul 16, 2021
@mp911de mp911de closed this as completed Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants