Skip to content

Commit d112a59

Browse files
bk-equityzensethmlarson
authored andcommitted
[7.x] Ensure size is >=0 when using slices
1 parent 46fb344 commit d112a59

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def __getitem__(self, n):
344344
# Elasticsearch won't get all results so we default to size: 10 if
345345
# stop not given.
346346
s._extra['from'] = n.start or 0
347-
s._extra['size'] = n.stop - (n.start or 0) if n.stop is not None else 10
347+
s._extra['size'] = max(0, n.stop - (n.start or 0) if n.stop is not None else 10)
348348
return s
349349
else: # This is an index lookup, equivalent to slicing by [n:n+1].
350350
# If negative index, abort.

test_elasticsearch_dsl/test_search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def test_slice():
237237
assert {'from': 0, 'size': 5} == s[:5].to_dict()
238238
assert {'from': 3, 'size': 10} == s[3:].to_dict()
239239
assert {'from': 0, 'size': 0} == s[0:0].to_dict()
240+
assert {'from': 20, 'size': 0} == s[20:0].to_dict()
240241

241242
def test_index():
242243
s = search.Search()

0 commit comments

Comments
 (0)