Skip to content

[Backport 8.x] Resolve _expand__to_dot default at runtime #1793

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 1 commit into from
Apr 29, 2024
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
4 changes: 3 additions & 1 deletion elasticsearch_dsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ def get_dsl_class(cls, name, default=None):
f"DSL class `{name}` does not exist in {cls._type_name}."
)

def __init__(self, _expand__to_dot=EXPAND__TO_DOT, **params):
def __init__(self, _expand__to_dot=None, **params):
if _expand__to_dot is None:
_expand__to_dot = EXPAND__TO_DOT
self._params = {}
for pname, pvalue in params.items():
if "__" in pname and _expand__to_dot:
Expand Down
11 changes: 10 additions & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from pytest import raises

from elasticsearch_dsl import function, query
from elasticsearch_dsl import function, query, utils


def test_empty_Q_is_match_all():
Expand Down Expand Up @@ -581,3 +581,12 @@ def test_script_score():
assert isinstance(q.query, query.MatchAll)
assert q.script == {"source": "...", "params": {}}
assert q.to_dict() == d


def test_expand_double_underscore_to_dot_setting():
q = query.Term(comment__count=2)
assert q.to_dict() == {"term": {"comment.count": 2}}
utils.EXPAND__TO_DOT = False
q = query.Term(comment__count=2)
assert q.to_dict() == {"term": {"comment__count": 2}}
utils.EXPAND__TO_DOT = True
Loading