Skip to content

Commit

Permalink
Ensure size is >=0 when using slices
Browse files Browse the repository at this point in the history
  • Loading branch information
bk-equityzen committed May 5, 2020
1 parent 46fb344 commit 5063955
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __getitem__(self, n):
# Elasticsearch won't get all results so we default to size: 10 if
# 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(0, n.stop - (n.start or 0) if n.stop is not None else 10)
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

0 comments on commit 5063955

Please sign in to comment.