couchbase / couchbase-python-client

Couchbase Python Client Library (Official)
https://www.couchbase.com/
Apache License 2.0
242 stars 110 forks source link

return in finally can swallow exceptions #57

Open iritkatriel opened 1 month ago

iritkatriel commented 1 month ago

In https://github.com/couchbase/couchbase-python-client/blob/465027c0253e3ba059eb1045793e5a3689bfa00f/acouchbase/transactions/transactions.py#L85

there is this snippet:

                try:
                    fn(self, *args, **kwargs)
                except SystemError as e:
                    ftr.set_exception(e.__cause__)
                except Exception as e:
                    ftr.set_exception(e)
                finally:
                    return ftr

It has a return statement in a finally block, which would swallow any in-flight exception.

This means that if a BaseException (such as KeyboardInterrupt) is raised from the try body, or any exception is raised from an except: clause, it will not propagate on as expected.

See also https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions.

thejcfactor commented 2 weeks ago

Hi @iritkatriel -- Thank you for filing the issue. I have created PYCBC-1636 in our JIRA system and will look to make changes as soon as possible.