def get_deleted_doc(db, doc_id, rev):
    res = db.get(doc_id, revs=True, rev=rev)
    start = res['_revisions']['start']
    ids = res['_revisions']['ids']
    prev_revision = "{}-{}".format(1-start, ids[1])
    try:
        doc = db.get(doc_id, rev=prev_revision)
    except ResourceNotFound:
        res.pop('_deleted')
        res.pop('_revisions')
        doc = res
    doc.pop('_rev')
    return doc
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cleanup/management/commands/undelete_docs.py/get_deleted_doc/swapped operands of `-`