(change, fetched_document)
This function ensures that the document fetched from a change matches the
    revision at which it was pushed to kafka at.

    See http://manage.dimagi.com/default.asp?237983 for more details

    :raises: DocumentMismatchError - Raised when the revisions of the fetched document
        and the change metadata do not match
This function ensures that the document fetched from a change matches the
    revision at which it was pushed to kafka at.
This function ensures that the document fetched from a change matches the revision at which it was pushed to kafka at .
def ensure_matched_revisions(change, fetched_document):
    """
    This function ensures that the document fetched from a change matches the
    revision at which it was pushed to kafka at.

    See http://manage.dimagi.com/default.asp?237983 for more details

    :raises: DocumentMismatchError - Raised when the revisions of the fetched document
        and the change metadata do not match
    """

    change_has_rev = change.metadata and change.metadata.document_rev is not None
    doc_has_rev = fetched_document and '_rev' in fetched_document
    if doc_has_rev and change_has_rev:

        doc_rev = fetched_document['_rev']
        change_rev = change.metadata.document_rev
        if doc_rev != change_rev:
            fetched_rev = _convert_rev_to_int(doc_rev)
            stored_rev = _convert_rev_to_int(change_rev)
            if fetched_rev < stored_rev or stored_rev == -1:
                message = "Mismatched revs for {}: Cloudant rev {} vs. Changes feed rev {}".format(
                    change.id,
                    doc_rev,
                    change_rev
                )
                pillow_logging.warning(message)
                raise DocumentMismatchError(message)
def ensure_matched_revisions ( change , fetched_document ) : change_has_rev = change . metadata and change . metadata . document_rev is not None doc_has_rev = fetched_document and '_rev' in fetched_document if doc_has_rev and change_has_rev : doc_rev = fetched_document [ '_rev' ] change_rev = change . metadata . document_rev if doc_rev != change_rev : fetched_rev = _convert_rev_to_int ( doc_rev ) stored_rev = _convert_rev_to_int ( change_rev ) if fetched_rev < stored_rev or stored_rev == - 1 : message = "Mismatched revs for {}: Cloudant rev {} vs. Changes feed rev {}" . format ( change . id , doc_rev , change_rev ) pillow_logging . warning ( message ) raise DocumentMismatchError ( message )