Skip to content

Commit

Permalink
Resolve _expand__to_dot default at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVermeulen42 authored and miguelgrinberg committed Apr 11, 2024
1 parent 0c0bdb7 commit 9b2d8f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 9b2d8f4

Please sign in to comment.