0

I'd like to know why the rev property of the couchdb.mapping.Document class is read-only attribute. Even id attribute can be set, and I need in my project to create a new Document with rev, which I obtain from CouchDB view. I know that rev is generated in CouchDB, but that's a pity that creators didn't predict such an exception. Moreover, in my humble opinion there should be a get method for the Document class with paramter: ids - it is many identifiers of documents.

@property
def rev(self):
    """The document revision.

    :rtype: basestring
    """
    if hasattr(self._data, 'rev'): # When data is client.Document
        return self._data.rev
    return self._data.get('_rev')
ady
  • 1,108
  • 13
  • 19

1 Answers1

1

You say "I need in my project to create a new Document with rev", but whether this is possible in this python lib or not, this is not possible in CouchDB itself so allowing you to set this in your lib would have no effect on your actual data.

The _rev in CouchDB is tightly managed by CouchDB for conflict resolution, you cannot change it from the values that CouchDB sets it to. (FWIW, CouchDB allows you to set any (unique) _id you like, which is why that's a writeable field in your python lib).

smathy
  • 26,283
  • 5
  • 48
  • 68
  • I wanted to work on exceptions. When I set _rev and want to update a document then if the provided document _rev is different than the actual one, it means I want to update the document from an obsolete version, so ResourceConflict exception is thrown and I can handle it. In this case, I don't have to check the version of a document beforehand I update the document (but eventually I changed my mind and know that I shouldn't use this internal CouchDB mechanism). – ady Aug 09 '12 at 14:16
  • Ok, that might be the longest time ever between answering and being accepted :) Thanks. – smathy Jan 14 '15 at 20:08