From c7c5db231d93c4e4f900d6f0cf2df6b4e2cb7027 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 11 Sep 2024 19:56:13 +0100 Subject: [PATCH] Fixed regression introduced in `Terms` query class (#1907) (#1909) (cherry picked from commit 8a72af97b071d0bf08aaf857289135aedc776924) Co-authored-by: Miguel Grinberg --- elasticsearch_dsl/query.py | 5 ++++- tests/test_query.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 67508a42..652b3d57 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -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): diff --git a/tests/test_query.py b/tests/test_query.py index 3f7c61ec..64d8ba2f 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -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()