File tree Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Expand file tree Collapse file tree 4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -295,7 +295,7 @@ async def update(
295295 merge (self , fields )
296296
297297 # prepare data for ES
298- values = self .to_dict ()
298+ values = self .to_dict (skip_empty = False )
299299
300300 # if fields were given: partial update
301301 body ["doc" ] = {k : values .get (k ) for k in fields .keys ()}
Original file line number Diff line number Diff line change @@ -293,7 +293,7 @@ def update(
293293 merge (self , fields )
294294
295295 # prepare data for ES
296- values = self .to_dict ()
296+ values = self .to_dict (skip_empty = False )
297297
298298 # if fields were given: partial update
299299 body ["doc" ] = {k : values .get (k ) for k in fields .keys ()}
Original file line number Diff line number Diff line change @@ -120,6 +120,13 @@ class Index:
120120 name = "test-serialization"
121121
122122
123+ class Tags (AsyncDocument ):
124+ tags = Keyword (multi = True )
125+
126+ class Index :
127+ name = "tags"
128+
129+
123130@pytest .mark .asyncio
124131async def test_serialization (async_write_client ):
125132 await SerializationDoc .init ()
@@ -504,6 +511,19 @@ async def test_save_updates_existing_doc(async_data_client):
504511 assert new_repo ["_seq_no" ] == elasticsearch_repo .meta .seq_no
505512
506513
514+ @pytest .mark .asyncio
515+ async def test_update_empty_field (async_client ):
516+ await Tags ._index .delete (ignore_unavailable = True )
517+ await Tags .init ()
518+ d = Tags (id = "123" , tags = ["a" , "b" ])
519+ await d .save (refresh = True )
520+ await d .update (tags = [], refresh = True )
521+ assert d .tags == []
522+
523+ r = await Tags .search ().execute ()
524+ assert r .hits [0 ].tags == []
525+
526+
507527@pytest .mark .asyncio
508528async def test_save_automatically_uses_seq_no_and_primary_term (async_data_client ):
509529 elasticsearch_repo = await Repository .get ("elasticsearch-dsl-py" )
Original file line number Diff line number Diff line change @@ -120,6 +120,13 @@ class Index:
120120 name = "test-serialization"
121121
122122
123+ class Tags (Document ):
124+ tags = Keyword (multi = True )
125+
126+ class Index :
127+ name = "tags"
128+
129+
123130@pytest .mark .sync
124131def test_serialization (write_client ):
125132 SerializationDoc .init ()
@@ -498,6 +505,19 @@ def test_save_updates_existing_doc(data_client):
498505 assert new_repo ["_seq_no" ] == elasticsearch_repo .meta .seq_no
499506
500507
508+ @pytest .mark .sync
509+ def test_update_empty_field (client ):
510+ Tags ._index .delete (ignore_unavailable = True )
511+ Tags .init ()
512+ d = Tags (id = "123" , tags = ["a" , "b" ])
513+ d .save (refresh = True )
514+ d .update (tags = [], refresh = True )
515+ assert d .tags == []
516+
517+ r = Tags .search ().execute ()
518+ assert r .hits [0 ].tags == []
519+
520+
501521@pytest .mark .sync
502522def test_save_automatically_uses_seq_no_and_primary_term (data_client ):
503523 elasticsearch_repo = Repository .get ("elasticsearch-dsl-py" )
You can’t perform that action at this time.
0 commit comments