cloudant / python-cloudant

A Python library for Cloudant and CouchDB
Apache License 2.0
163 stars 55 forks source link

Document.atomic context manager #428

Closed aogier closed 5 years ago

aogier commented 5 years ago

Checklist

Description

This PR implements a Document.atomic context manager that don't save a document if there is any uncatched exception in inner code block. Tentatively fixes #427.

Approach

As this change could be breaking (in fact it change a default behaviour) I've decided to implement a brand new context manager using python's contextlib. When it's needed, one could use atomic as a context manager:

with Document(self.db, 'julia006').atomic() as doc:

Context Manager implementation follow current one, in fact it uses the same dunders.

Schema & API Changes

Security and Privacy

Testing

Monitoring and Logging

smithsz commented 5 years ago

Thanks again for this. We've decided to change the default behaviour. I've made the change in .__exit__ and stolen your tests (see #434).