@transaction intercept commit argument; commit / release here.
This commit is contained in:
parent
04f3f6f297
commit
203fb9e00f
1 changed files with 12 additions and 2 deletions
|
@ -78,12 +78,22 @@ def transaction(method):
|
||||||
@functools.wraps(method)
|
@functools.wraps(method)
|
||||||
def wrapped_transaction(self, *args, **kwargs):
|
def wrapped_transaction(self, *args, **kwargs):
|
||||||
photodb = _get_relevant_photodb(self)
|
photodb = _get_relevant_photodb(self)
|
||||||
|
|
||||||
|
commit = kwargs.pop('commit', False)
|
||||||
|
is_root = len(photodb.savepoints) == 0
|
||||||
|
|
||||||
savepoint_id = photodb.savepoint(message=method.__qualname__)
|
savepoint_id = photodb.savepoint(message=method.__qualname__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = method(self, *args, **kwargs)
|
result = method(self, *args, **kwargs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
photodb.rollback(savepoint=savepoint_id)
|
photodb.rollback(savepoint=savepoint_id)
|
||||||
raise
|
raise
|
||||||
else:
|
|
||||||
return result
|
if commit:
|
||||||
|
photodb.commit(message=method.__qualname__)
|
||||||
|
elif not is_root:
|
||||||
|
photodb.release_savepoint(savepoint=savepoint_id)
|
||||||
|
return result
|
||||||
|
|
||||||
return wrapped_transaction
|
return wrapped_transaction
|
||||||
|
|
Loading…
Reference in a new issue