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

Avoid negative sizes in Search slice #1360

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions elasticsearch_dsl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def __getitem__(self, n):
# stop not given.
s._extra['from'] = n.start or 0
s._extra['size'] = n.stop - (n.start or 0) if n.stop is not None else 10
s._extra['size'] = max(s._extra['size'], 0)
sethmlarson marked this conversation as resolved.
Show resolved Hide resolved
return s
else: # This is an index lookup, equivalent to slicing by [n:n+1].
# If negative index, abort.
Expand Down
1 change: 1 addition & 0 deletions test_elasticsearch_dsl/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def test_slice():
assert {'from': 0, 'size': 5} == s[:5].to_dict()
assert {'from': 3, 'size': 10} == s[3:].to_dict()
assert {'from': 0, 'size': 0} == s[0:0].to_dict()
assert {'from': 20, 'size': 0} == s[20:0].to_dict()

def test_index():
s = search.Search()
Expand Down