From 5bc9a6268587fecffbcf104c0ef31573ce0c050a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 22 Aug 2024 16:23:29 +0100 Subject: [PATCH] Accept Terms value to be any iterable (#1887) (#1889) Co-authored-by: Roxane (cherry picked from commit 8cc2ed25969b35ec72970096895af121fc5a27ef) Co-authored-by: roxanebellot --- elasticsearch_dsl/query.py | 3 +++ tests/test_query.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/elasticsearch_dsl/query.py b/elasticsearch_dsl/query.py index 993213c6..67508a42 100644 --- a/elasticsearch_dsl/query.py +++ b/elasticsearch_dsl/query.py @@ -550,6 +550,9 @@ class Term(Query): class Terms(Query): name = "terms" + def _setattr(self, name: str, value: Any) -> None: + super()._setattr(name, list(value)) + class TermsSet(Query): name = "terms_set" diff --git a/tests/test_query.py b/tests/test_query.py index 601f5102..3f7c61ec 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -77,6 +77,15 @@ def test_term_to_dict() -> None: assert {"term": {"_type": "article"}} == query.Term(_type="article").to_dict() +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") + ).to_dict() + + def test_bool_to_dict() -> None: bool = query.Bool(must=[query.Match(f="value")], should=[])