Skip to content

Commit 601f7e9

Browse files
konstinhonzakral
authored andcommitted
Don't override existing extras in update_from_dict
1 parent 11bccf8 commit 601f7e9

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

docs/update_by_query.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ the data from the dict:
105105
106106
ubq = UpdateByQuery.from_dict({"query": {"match": {"title": "python"}}})
107107
108-
If you wish to modify an existing ``Update By Query`` object, overriding it'ubq
108+
If you wish to modify an existing ``Update By Query`` object, overriding it's
109109
properties, instead use the ``update_from_dict`` method that alters an instance
110110
**in-place**:
111111

elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def update_from_dict(self, d):
441441
s.setdefault('text', text)
442442
if 'script_fields' in d:
443443
self._script_fields = d.pop('script_fields')
444-
self._extra = d
444+
self._extra.update(d)
445445
return self
446446

447447
def script_fields(self, **kwargs):

elasticsearch_dsl/update_by_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update_from_dict(self, d):
8585
self.query._proxied = Q(d.pop('query'))
8686
if 'script' in d:
8787
self._script = d.pop('script')
88-
self._extra = d
88+
self._extra.update(d)
8989
return self
9090

9191
def script(self, **kwargs):

test_elasticsearch_dsl/test_search.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,3 +530,18 @@ def test_delete_by_query(mock_client):
530530
index=None,
531531
body={"query": {"match": {"lang": "java"}}}
532532
)
533+
534+
def test_update_from_dict():
535+
s = search.Search()
536+
s.update_from_dict({"indices_boost": [{"important-documents": 2}]})
537+
s.update_from_dict({"_source": ["id", "name"]})
538+
539+
assert {
540+
'indices_boost': [{
541+
'important-documents': 2
542+
}],
543+
'_source': [
544+
'id',
545+
'name'
546+
]
547+
} == s.to_dict()

0 commit comments

Comments
 (0)