cloudant / python-cloudant

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

document.update_field() raises 409 after successful retry #393

Closed andy-maier closed 6 years ago

andy-maier commented 6 years ago

Bug Description

1. Steps to reproduce and the simplest code sample possible to demonstrate the issue

The Document.update_field() method raises an HTTPError(409) exception if it succeeds with its retries without exhausting the max retries.

Here is the code in Document._update_field() (see here):

        # Attempt to save, retrying conflicts up to max_tries.
        try:
            self.save()
        except requests.HTTPError as ex:
            if tries < max_tries and ex.response.status_code == 409:
                self._update_field(
                    action, field, value, max_tries, tries=tries+1)
            raise

The raise statement should be in an else: clause if the previous if statement.

If you need a script that reproduces this, let me know, but it is too long to paste here (I think), and from looking at the code, the issue should be obvious.

2. What you expected to happen

The Document.update_field() method should not raise an HTTPError(409) exception if it ended up with a successful retry without exhausting its max retries. Only if the max retries are exhausted, should it raise the exception.

The description of the Document.update_field() method should document that.

There should be test cases that verify that case. :-)

3. What actually happened

See above.

Environment details