Skip to content

Commit 5a6a231

Browse files
Resolve _expand__to_dot default at runtime (elastic#1634)
* Resolve _expand__to_dot default at runtime * code formatting --------- Co-authored-by: Miguel Grinberg <[email protected]>
1 parent 0c0bdb7 commit 5a6a231

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

elasticsearch_dsl/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ def get_dsl_class(cls, name, default=None):
252252
f"DSL class `{name}` does not exist in {cls._type_name}."
253253
)
254254

255-
def __init__(self, _expand__to_dot=EXPAND__TO_DOT, **params):
255+
def __init__(self, _expand__to_dot=None, **params):
256+
if _expand__to_dot is None:
257+
_expand__to_dot = EXPAND__TO_DOT
256258
self._params = {}
257259
for pname, pvalue in params.items():
258260
if "__" in pname and _expand__to_dot:

tests/test_query.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from pytest import raises
1919

20-
from elasticsearch_dsl import function, query
20+
from elasticsearch_dsl import function, query, utils
2121

2222

2323
def test_empty_Q_is_match_all():
@@ -581,3 +581,12 @@ def test_script_score():
581581
assert isinstance(q.query, query.MatchAll)
582582
assert q.script == {"source": "...", "params": {}}
583583
assert q.to_dict() == d
584+
585+
586+
def test_expand_double_underscore_to_dot_setting():
587+
q = query.Term(comment__count=2)
588+
assert q.to_dict() == {"term": {"comment.count": 2}}
589+
utils.EXPAND__TO_DOT = False
590+
q = query.Term(comment__count=2)
591+
assert q.to_dict() == {"term": {"comment__count": 2}}
592+
utils.EXPAND__TO_DOT = True

0 commit comments

Comments
 (0)