diff --git a/elasticsearch_dsl/search_base.py b/elasticsearch_dsl/search_base.py index 50117e1b..c8816d59 100644 --- a/elasticsearch_dsl/search_base.py +++ b/elasticsearch_dsl/search_base.py @@ -17,6 +17,7 @@ import collections.abc import copy +import warnings from .aggs import A, AggBase from .exceptions import IllegalOperation @@ -348,6 +349,15 @@ def __getitem__(self, n): """ s = self._clone() + if "from" in s._extra or "size" in s._extra: + warnings.warn( + "Slicing multiple times currently has no effect but will be supported " + "in a future release. See https://github.com/elastic/elasticsearch-dsl-py/pull/1771 " + "for more details", + DeprecationWarning, + stacklevel=2, + ) + if isinstance(n, slice): # If negative slicing, abort. if n.start and n.start < 0 or n.stop and n.stop < 0: diff --git a/tests/_async/test_search.py b/tests/_async/test_search.py index 1f7ad1de..6abc8bca 100644 --- a/tests/_async/test_search.py +++ b/tests/_async/test_search.py @@ -17,7 +17,7 @@ from copy import deepcopy -from pytest import raises +from pytest import raises, warns from elasticsearch_dsl import AsyncSearch, Document, Q, query from elasticsearch_dsl.exceptions import IllegalOperation @@ -363,6 +363,12 @@ def test_slice(): assert {"from": 20, "size": 0} == s[20:0].to_dict() +def test_slice_twice(): + with warns(DeprecationWarning, match="Slicing multiple times .*"): + s = AsyncSearch() + s[10:20][2:] + + def test_index(): s = AsyncSearch() assert {"from": 3, "size": 1} == s[3].to_dict() diff --git a/tests/_sync/test_search.py b/tests/_sync/test_search.py index 306b09f5..255b1eeb 100644 --- a/tests/_sync/test_search.py +++ b/tests/_sync/test_search.py @@ -17,7 +17,7 @@ from copy import deepcopy -from pytest import raises +from pytest import raises, warns from elasticsearch_dsl import Document, Q, Search, query from elasticsearch_dsl.exceptions import IllegalOperation @@ -363,6 +363,12 @@ def test_slice(): assert {"from": 20, "size": 0} == s[20:0].to_dict() +def test_slice_twice(): + with warns(DeprecationWarning, match="Slicing multiple times .*"): + s = Search() + s[10:20][2:] + + def test_index(): s = Search() assert {"from": 3, "size": 1} == s[3].to_dict()