File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -401,12 +401,10 @@ def update(
401
401
402
402
# extract routing etc from meta
403
403
doc_meta = {k : self .meta [k ] for k in DOC_META_FIELDS if k in self .meta }
404
-
405
404
if retry_on_conflict is not None :
406
405
doc_meta ["retry_on_conflict" ] = retry_on_conflict
407
406
408
- # Optimistic concurrency control
409
- if "seq_no" in self .meta and "primary_term" in self .meta :
407
+ if retry_on_conflict in (None , 0 ) and "seq_no" in self .meta and "primary_term" in self .meta :
410
408
doc_meta ["if_seq_no" ] = self .meta ["seq_no" ]
411
409
doc_meta ["if_primary_term" ] = self .meta ["primary_term" ]
412
410
Original file line number Diff line number Diff line change @@ -234,6 +234,20 @@ def test_update_script(write_client):
234
234
assert w .views == 47
235
235
236
236
237
+ def test_update_retry_on_conflict (write_client ):
238
+ Wiki .init ()
239
+ w = Wiki (owner = User (name = "Honza Kral" ), _id = "elasticsearch-py" , views = 42 )
240
+ w .save ()
241
+
242
+ w1 = Wiki .get (id = "elasticsearch-py" )
243
+ w2 = Wiki .get (id = "elasticsearch-py" )
244
+ w1 .update (script = "ctx._source.views += params.inc" , inc = 5 , retry_on_conflict = 1 )
245
+ w2 .update (script = "ctx._source.views += params.inc" , inc = 5 , retry_on_conflict = 1 )
246
+
247
+ w = Wiki .get (id = "elasticsearch-py" )
248
+ assert w .views == 52
249
+
250
+
237
251
def test_save_and_update_return_doc_meta (write_client ):
238
252
Wiki .init ()
239
253
w = Wiki (owner = User (name = "Honza Kral" ), _id = "elasticsearch-py" , views = 42 )
You can’t perform that action at this time.
0 commit comments