From 9328600355be9b66fdb5aafbdccdbfb079e8d83c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 29 Jul 2018 16:03:04 -0700 Subject: [PATCH] Add message parameter to PDB.savepoint for better logging. Helps to have a visual on which methods are creating the saves. --- etiquette/decorators.py | 2 +- etiquette/photodb.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/etiquette/decorators.py b/etiquette/decorators.py index 0f4b027..9ee6964 100644 --- a/etiquette/decorators.py +++ b/etiquette/decorators.py @@ -78,7 +78,7 @@ def transaction(method): @functools.wraps(method) def wrapped_transaction(self, *args, **kwargs): photodb = _get_relevant_photodb(self) - savepoint_id = photodb.savepoint() + savepoint_id = photodb.savepoint(message=method.__qualname__) try: result = method(self, *args, **kwargs) except Exception as e: diff --git a/etiquette/photodb.py b/etiquette/photodb.py index a13d724..daebe8e 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -720,9 +720,12 @@ class PDBSQLMixin: if item == restore_to: break - def savepoint(self): + def savepoint(self, message=None): savepoint_id = helpers.random_hex(length=16) - self.log.debug('Savepoint %s.', savepoint_id) + if message: + self.log.debug('Savepoint %s for %s.', savepoint_id, message) + else: + self.log.debug('Savepoint %s.', savepoint_id) query = 'SAVEPOINT "%s"' % savepoint_id self.sql.execute(query) self.savepoints.append(savepoint_id)