File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -406,7 +406,11 @@ def update(
406
406
doc_meta ["retry_on_conflict" ] = retry_on_conflict
407
407
408
408
# Optimistic concurrency control
409
- if "seq_no" in self .meta and "primary_term" in self .meta :
409
+ if (
410
+ retry_on_conflict in (None , 0 )
411
+ and "seq_no" in self .meta
412
+ and "primary_term" in self .meta
413
+ ):
410
414
doc_meta ["if_seq_no" ] = self .meta ["seq_no" ]
411
415
doc_meta ["if_primary_term" ] = self .meta ["primary_term" ]
412
416
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