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(
295
295
merge (self , fields )
296
296
297
297
# prepare data for ES
298
- values = self .to_dict ()
298
+ values = self .to_dict (skip_empty = False )
299
299
300
300
# if fields were given: partial update
301
301
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(
293
293
merge (self , fields )
294
294
295
295
# prepare data for ES
296
- values = self .to_dict ()
296
+ values = self .to_dict (skip_empty = False )
297
297
298
298
# if fields were given: partial update
299
299
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:
120
120
name = "test-serialization"
121
121
122
122
123
+ class Tags (AsyncDocument ):
124
+ tags = Keyword (multi = True )
125
+
126
+ class Index :
127
+ name = "tags"
128
+
129
+
123
130
@pytest .mark .asyncio
124
131
async def test_serialization (async_write_client ):
125
132
await SerializationDoc .init ()
@@ -504,6 +511,19 @@ async def test_save_updates_existing_doc(async_data_client):
504
511
assert new_repo ["_seq_no" ] == elasticsearch_repo .meta .seq_no
505
512
506
513
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
+
507
527
@pytest .mark .asyncio
508
528
async def test_save_automatically_uses_seq_no_and_primary_term (async_data_client ):
509
529
elasticsearch_repo = await Repository .get ("elasticsearch-dsl-py" )
Original file line number Diff line number Diff line change @@ -120,6 +120,13 @@ class Index:
120
120
name = "test-serialization"
121
121
122
122
123
+ class Tags (Document ):
124
+ tags = Keyword (multi = True )
125
+
126
+ class Index :
127
+ name = "tags"
128
+
129
+
123
130
@pytest .mark .sync
124
131
def test_serialization (write_client ):
125
132
SerializationDoc .init ()
@@ -498,6 +505,19 @@ def test_save_updates_existing_doc(data_client):
498
505
assert new_repo ["_seq_no" ] == elasticsearch_repo .meta .seq_no
499
506
500
507
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
+
501
521
@pytest .mark .sync
502
522
def test_save_automatically_uses_seq_no_and_primary_term (data_client ):
503
523
elasticsearch_repo = Repository .get ("elasticsearch-dsl-py" )
You can’t perform that action at this time.
0 commit comments