Skip to content

Commit

Permalink
Fixed regression introduced in Terms query class (#1907) (#1909)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8a72af9)

Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
  • Loading branch information
github-actions[bot] and miguelgrinberg authored Sep 11, 2024
1 parent afd340b commit c7c5db2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ class Terms(Query):
name = "terms"

def _setattr(self, name: str, value: Any) -> None:
super()._setattr(name, list(value))
# here we convert any iterables that are not strings to lists
if hasattr(value, "__iter__") and not isinstance(value, (str, list)):
value = list(value)
super()._setattr(name, value)


class TermsSet(Query):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def test_terms_to_dict() -> None:
assert {"terms": {"_type": ["article", "section"]}} == query.Terms(
_type=["article", "section"]
).to_dict()
assert {"terms": {"_type": ["article", "section"]}} == query.Terms(
_type=("article", "section")
assert {"terms": {"_type": ["article", "section"], "boost": 1.1}} == query.Terms(
_type=("article", "section"), boost=1.1
).to_dict()


Expand Down

0 comments on commit c7c5db2

Please sign in to comment.