I am trying to:
- read a value from a document
- update a document.
However, I would like the transaction to fail if another process made a modification to the same document between 1 and 2.
I simulated it with the debugger (stopping after 1, make a modification on the document and resume). As a result, the transaction does not seem to be applied but I do not get any error. I would like a real failure with an exception. How can I achieve that?
transaction = db.transaction()
doc_ref = db.collection('mycollection').document('mydoc')
@firestore.transactional
def update_in_transaction(transaction, doc_ref):
snapshot = doc_ref.get(transaction=transaction)
my_value = snapshot.get(u'my_value')
transaction.update(doc_ref, {
u'my_value': 'someothervalue'
})
update_in_transaction(transaction, doc_ref)