From 203fb9e00f6cb72a59321246584f0e54614abc05 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 19 Feb 2020 22:36:00 -0800 Subject: [PATCH] @transaction intercept commit argument; commit / release here. --- etiquette/decorators.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/etiquette/decorators.py b/etiquette/decorators.py index f457af7..16ca271 100644 --- a/etiquette/decorators.py +++ b/etiquette/decorators.py @@ -78,12 +78,22 @@ def transaction(method): @functools.wraps(method) def wrapped_transaction(self, *args, **kwargs): photodb = _get_relevant_photodb(self) + + commit = kwargs.pop('commit', False) + is_root = len(photodb.savepoints) == 0 + savepoint_id = photodb.savepoint(message=method.__qualname__) + try: result = method(self, *args, **kwargs) except Exception as e: photodb.rollback(savepoint=savepoint_id) 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