Repository: elastic/elasticsearch-dsl-py (language: python)

Issue:
Terms query errors when passing the boost parameter
When I upgraded to the latest version of the Elasticsearch-DSL library, I found a bug that you cannot pass the boost parameter anymore, because it tries to parse everything as a list. This is an example that fails:

```
query.Terms(title=["Something"], boost=2)
```

Hope the problem is clear.




Discussion / hints:
Thanks, yes, this has been reported already in https://github.com/elastic/elasticsearch-dsl-py/pull/1904. We will publish a fix soon.

Fix patch:
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):


Test patch:
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()