Skip to content

Commit

Permalink
Do not pass if_seq_no and if_primary_term to request if retry_on_conf…
Browse files Browse the repository at this point in the history
…lict is not none
  • Loading branch information
armando committed Dec 8, 2020
1 parent 147ff11 commit 0172d6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def update(
doc_meta["retry_on_conflict"] = retry_on_conflict

# Optimistic concurrency control
if "seq_no" in self.meta and "primary_term" in self.meta:
if retry_on_conflict in (None, 0) and "seq_no" in self.meta and "primary_term" in self.meta:
doc_meta["if_seq_no"] = self.meta["seq_no"]
doc_meta["if_primary_term"] = self.meta["primary_term"]

Expand Down
14 changes: 14 additions & 0 deletions tests/test_integration/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ def test_update_script(write_client):
assert w.views == 47


def test_update_retry_on_conflict(write_client):
Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42)
w.save()

w1 = Wiki.get(id="elasticsearch-py")
w2 = Wiki.get(id="elasticsearch-py")
w1.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1)
w2.update(script="ctx._source.views += params.inc", inc=5, retry_on_conflict=1)

w = Wiki.get(id="elasticsearch-py")
assert w.views == 52


def test_save_and_update_return_doc_meta(write_client):
Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py", views=42)
Expand Down

0 comments on commit 0172d6e

Please sign in to comment.