Skip to content

Commit

Permalink
Optimistic concurrent control for Document.delete (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored and honzakral committed May 20, 2019
1 parent 2371311 commit e77ea75
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions elasticsearch_dsl/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ def delete(self, using=None, index=None, **kwargs):
for k in DOC_META_FIELDS
if k in self.meta
}

# Optimistic concurrency control
if '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']

doc_meta.update(kwargs)
es.delete(
index=self._get_index(index),
Expand Down
7 changes: 7 additions & 0 deletions test_elasticsearch_dsl/test_integration/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ def test_save_automatically_uses_seq_no_and_primary_term(data_client):
with raises(ConflictError):
elasticsearch_repo.save()

def test_delete_automatically_uses_seq_no_and_primary_term(data_client):
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')
elasticsearch_repo.meta.seq_no += 1

with raises(ConflictError):
elasticsearch_repo.delete()

def assert_doc_equals(expected, actual):
for f in expected:
assert f in actual
Expand Down

0 comments on commit e77ea75

Please sign in to comment.