Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions couchdbkit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,17 @@ def save_doc(self, doc, encode_attachments=True, force_update=False,
couch_doc = Document(self.cloudant_database, docid)
couch_doc.update(doc1)
try:
couch_doc.save()
# Copied from Document.save to ensure that a deleted doc cannot be saved.
headers = {}
headers.setdefault('Content-Type', 'application/json')
put_resp = couch_doc.r_session.put(
couch_doc.document_url,
data=couch_doc.json(),
headers=headers
)
put_resp.raise_for_status()
data = put_resp.json()
super(Document, couch_doc).__setitem__('_rev', data['rev'])
except HTTPError as e:
if e.response.status_code != 409:
raise
Expand Down Expand Up @@ -716,7 +726,10 @@ def delete_doc(self, doc, **params):
couch_doc['_rev'] = doc1['_rev']
elif isinstance(doc1, six.string_types): # we get a docid
couch_doc = Document(self.cloudant_database, doc1)
couch_doc['_rev'] = self.get_rev(doc1)
try:
couch_doc['_rev'] = self.get_rev(doc1)
except ResourceNotFound:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If get_rev is using requests I think it would return HttpError right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It catches a 404 error and raises a ResourceNotFound error instead

raise ResourceConflict

# manual request because cloudant library doesn't return result
res = self._request_session.delete(
Expand Down
2 changes: 1 addition & 1 deletion couchdbkit/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

from __future__ import absolute_import
from six.moves import map
version_info = (0, 9, 0, 3, 6)
version_info = (0, 9, 0, 3, 7)
__version__ = ".".join(map(str, version_info))