I have a python program that accesses a couchDB database, creates new documents and updates existing ones. For a given database, db, and document, Doc, I try to take care and reload the document before each modification:
somedoc = Doc.load(db,id)
before updating via
doc.store(db)
As far as I am aware this shouldn't be necessary, as doc.rev should be updated each time store is called. BUT ... I am getting conflict messages:
couchdb.http.ResourceConflict: (u'conflict', u'Document update conflict.')
Is there any way of just forcing no update and a warning message rather than having a fatal error upon these conflicts. Or, better, is there some way of quickly checking the document revision number - the db is being accessed by two scripts that both update, but both are careful to load each doc, make modifications quickly and update the db in as little time as possible to minimise the chance of a conflict....
Cheers
I still haven't worked out where the resource conflict is coming from, given that just before storing a doc I check that the revision is correct:
latestRev = CouchDoc.load(db,doc.id)
if latestRev.rev != doc.rev:
print 'revision mismatch ' + doc.rev + '\t' + revs.rev
else:
doc.store(db)
However, there is an easy way round the conflict causing a fatal error (new to python, so didn't think of doing this before):
try:
doc.store(db)
except couchdb.http.ResourceConflict:
latestDoc = ConflictDoc.load(db,doc.id)
This does require that any updates to doc before the try command are redone before storing again when couchDB throws a ResourceConflict.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With