Skip to content

Fixed use of dictionaries as values in Terms query (#1921) #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading