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

Fix importing collapse from dict #1689

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions elasticsearch_dsl/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def __init__(self, using="default", index=None, doc_type=None, extra=None):

self._doc_type = []
self._doc_type_map = {}
self._collapse = {}
if isinstance(doc_type, (tuple, list)):
self._doc_type.extend(doc_type)
elif isinstance(doc_type, collections.abc.Mapping):
Expand Down Expand Up @@ -294,7 +293,6 @@ def _clone(self):
s = self.__class__(
using=self._using, index=self._index, doc_type=self._doc_type
)
s._collapse = self._collapse.copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, thanks! Can you please move self._collapse = {} to Search.__init__ too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the Search class already initializes self._collapse. The one in Request should not be there, I'm removing it.

s._doc_type_map = self._doc_type_map.copy()
s._extra = self._extra.copy()
s._params = self._params.copy()
Expand Down Expand Up @@ -408,6 +406,7 @@ def _clone(self):
s = super()._clone()

s._response_class = self._response_class
s._collapse = self._collapse.copy()
s._sort = self._sort[:]
s._source = copy.copy(self._source) if self._source is not None else None
s._highlight = self._highlight.copy()
Expand Down Expand Up @@ -446,6 +445,8 @@ def update_from_dict(self, d):
self.aggs._params = {
"aggs": {name: A(value) for (name, value) in aggs.items()}
}
if "collapse" in d:
self._collapse = d.pop("collapse")
if "sort" in d:
self._sort = d.pop("sort")
if "_source" in d:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,12 @@ def test_update_from_dict():
s = search.Search()
s.update_from_dict({"indices_boost": [{"important-documents": 2}]})
s.update_from_dict({"_source": ["id", "name"]})
s.update_from_dict({"collapse": {"field": "user_id"}})

assert {
"indices_boost": [{"important-documents": 2}],
"_source": ["id", "name"],
"collapse": {"field": "user_id"},
} == s.to_dict()


Expand Down
Loading