Skip to content

Commit d614b66

Browse files
committed
Only assign data back into doc if true-ish or has been present
Fixes elastic#303
1 parent 6fa1f82 commit d614b66

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

elasticsearch_dsl/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,13 @@ def clean_fields(self):
434434
data = self._d_.get(name, None)
435435
try:
436436
# save the cleaned value
437-
self._d_[name] = field.clean(data)
437+
data = field.clean(data)
438438
except ValidationException as e:
439439
errors.setdefault(name, []).append(e)
440440

441+
if name in self._d_ or data not in ([], {}, None):
442+
self._d_[name] = data
443+
441444
if errors:
442445
raise ValidationException(errors)
443446

test_elasticsearch_dsl/test_document.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ class MyMultiSubDoc(MyDoc2, MySubDoc):
3232
class DocWithNested(document.DocType):
3333
comments = field.Nested(properties={'title': field.String()})
3434

35+
class SimpleCommit(document.DocType):
36+
files = field.String(multi=True)
37+
38+
class Meta:
39+
index = 'test-git'
40+
41+
def test_multi_works_after_doc_has_been_saved(write_client):
42+
c = SimpleCommit()
43+
c.full_clean()
44+
c.files.append('setup.py')
45+
46+
assert c.to_dict() == {'files': ['setup.py']}
47+
3548
def test_null_value_for_object():
3649
d = MyDoc(inner=None)
3750

@@ -317,6 +330,6 @@ def test_search_with_custom_alias_and_index(mock_client):
317330
search_object = MyDoc.search(
318331
using="staging",
319332
index=["custom_index1", "custom_index2"])
320-
333+
321334
assert search_object._using == "staging"
322335
assert search_object._index == ["custom_index1", "custom_index2"]

0 commit comments

Comments
 (0)