Skip to content

Commit

Permalink
Fixed use of dictionaries as values in Terms query (#1921) (#1922)
Browse files Browse the repository at this point in the history
Fixes #1920
  • Loading branch information
miguelgrinberg authored Oct 7, 2024
1 parent 3f072c3 commit e49d851
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class Terms(Query):

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

Expand Down
8 changes: 8 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def test_terms_to_dict() -> None:
assert {"terms": {"_type": ["article", "section"], "boost": 1.1}} == query.Terms(
_type=("article", "section"), boost=1.1
).to_dict()
assert {"terms": {"_type": "article", "boost": 1.1}} == query.Terms(
_type="article", boost=1.1
).to_dict()
assert {
"terms": {"_id": {"index": "my-other-index", "id": "my-id"}, "boost": 1.1}
} == query.Terms(
_id={"index": "my-other-index", "id": "my-id"}, boost=1.1
).to_dict()


def test_bool_to_dict() -> None:
Expand Down

0 comments on commit e49d851

Please sign in to comment.