-
-
Notifications
You must be signed in to change notification settings - Fork 827
Closed
Description
Doom(able|ed) transactions are a concept a few databases have to guard against wrong error handling but also allow easy transaction control / abortion. We would only use it as a fail-safe against incorrect error handling and also "strange" issues with networking should they occur.
It could look like this:
# Sketch code, not fleshed out, certainly not tested.
class Repository:
@staticmethod
def exception_dooms(whitelist=(,)):
"""All exceptions not on *whitelist* raised in the decorated method will doom the current transaction."""
def decorator(method):
def meth_wrapper(self, *args, **kwargs):
try:
return method(self, ...)
except Exception as exc:
if type(exc) not in whitelist:
self.doom_transaction(exc)
raise
return meth_wrapper
return decorator
def doom_transaction(self, exception=None):
self.transaction_doomed = True
self.transaction_doomed_by = exception
def begin_transaction(self):
...
self.transaction_doomed = False
@exception_dooms()
def write_stuff(self, ...):
# do something
if bad:
raise OSError
@exception_dooms(whitelist=(ObjectNotFound,))
def get(self, id):
...
def commit(self):
if self.transaction_doomed:
log_exception(self.transaction_doomed_by)
assert not self.transaction_doomed, 'Tried to commit doomed transaction'
...Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels