feat: Implement inverted range check for _all_docs #5874
Closed
+83
−10
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.
This PR implements a validation check for _all_docs requests to ensure that start_key is not greater than end_key (or vice versa when descending=true).
Previously, _all_docs queries with inverted ranges would return empty results without a clear indication of the error. This change aligns the behavior of _all_docs with _view, which already rejects inverted ranges with a 400 Bad Request.
Users providing an invalid range will now receive the following error:
{"error":"query_parse_error","reason":"No rows can match your key range, reverse your start_key and end_key or set descending=true"}
Testing recommendations
I have added two new test cases to the existing
src/chttpd/test/eunit/chttpd_view_test.erl
suite:
t_all_docs_with_inverted_range - verifies 400 error for inverted ranges
t_all_docs_with_inverted_range_descending - verifies correct behavior with descending=true
Manual testing can be done by querying _all_docs with an inverted range and verifying the 400 response.
Related Issues or Pull Requests
Fixes #5866
Checklist
This is my own work, I did not use AI, LLM's or similar technology
Code is written and works correctly
Changes are covered by tests
Any new configurable parameters are documented in
rel/overlay/etc/default.ini
Documentation changes were made in the src/docs folder
Documentation changes were backported (separated PR) to affected branches