File tree 4 files changed +56
-2
lines changed
4 files changed +56
-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,26 @@ 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 (wait_for_active_shards = 1 )
520
+ await d .update (tags = [])
521
+ assert d .tags == []
522
+
523
+ while True :
524
+ try :
525
+ r = await Tags .search ().execute ()
526
+ d = r .hits [0 ]
527
+ except IndexError :
528
+ continue
529
+ else :
530
+ break
531
+ assert d .tags == []
532
+
533
+
507
534
@pytest .mark .asyncio
508
535
async def test_save_automatically_uses_seq_no_and_primary_term (async_data_client ):
509
536
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,26 @@ 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 (wait_for_active_shards = 1 )
514
+ d .update (tags = [])
515
+ assert d .tags == []
516
+
517
+ while True :
518
+ try :
519
+ r = Tags .search ().execute ()
520
+ d = r .hits [0 ]
521
+ except IndexError :
522
+ continue
523
+ else :
524
+ break
525
+ assert d .tags == []
526
+
527
+
501
528
@pytest .mark .sync
502
529
def test_save_automatically_uses_seq_no_and_primary_term (data_client ):
503
530
elasticsearch_repo = Repository .get ("elasticsearch-dsl-py" )
You can’t perform that action at this time.
0 commit comments