PhotoDB.rollback without savepoint should roll all, like real sql.
In sqlite3, rollback without a savepoint undoes the entire pending transaction stack, whereas I was just popping the last save. This change makes it match real sqlite. Also the only current call for rollback is in the @transaction decorator which is already explicit.
This commit is contained in:
parent
9e0051ca9c
commit
e7c90faf79
1 changed files with 19 additions and 19 deletions
|
@ -715,27 +715,27 @@ class PDBSQLMixin:
|
||||||
savepoint was created. Keep in mind that a @transaction savepoint is
|
savepoint was created. Keep in mind that a @transaction savepoint is
|
||||||
always created *before* the method actually does anything.
|
always created *before* the method actually does anything.
|
||||||
|
|
||||||
If no savepoint is provided then just roll back the most recent save.
|
If no savepoint is provided then rollback the entire transaction.
|
||||||
'''
|
'''
|
||||||
if savepoint is None:
|
if savepoint is not None and savepoint not in self.savepoints:
|
||||||
try:
|
self.log.warn('Tried to restore nonexistent savepoint %s.', savepoint)
|
||||||
savepoint = self.savepoints.pop(-1)
|
return
|
||||||
except IndexError:
|
|
||||||
self.log.debug('Nothing to roll back.')
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
# Will reassign after everything goes well.
|
|
||||||
_savepoints = helpers.slice_before(self.savepoints, savepoint)
|
|
||||||
except ValueError:
|
|
||||||
self.log.warn('Tried to restore nonexistent savepoint %s.', savepoint)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.log.debug('Rolling back to %s', savepoint)
|
if len(self.savepoints) == 0:
|
||||||
query = f'ROLLBACK TO "{savepoint}"'
|
self.log.debug('Nothing to roll back.')
|
||||||
self.sql_execute(query)
|
return
|
||||||
self.savepoints = _savepoints
|
|
||||||
self.on_commit_queue = helpers.slice_before(self.on_commit_queue, savepoint)
|
if savepoint is not None:
|
||||||
|
self.log.debug('Rolling back to %s', savepoint)
|
||||||
|
self.sql_execute(f'ROLLBACK TO "{savepoint}"')
|
||||||
|
self.savepoints = helpers.slice_before(self.savepoints, savepoint)
|
||||||
|
self.on_commit_queue = helpers.slice_before(self.on_commit_queue, savepoint)
|
||||||
|
|
||||||
|
else:
|
||||||
|
self.log.debug('Rolling back.')
|
||||||
|
self.sql_execute('ROLLBACK')
|
||||||
|
self.savepoints = []
|
||||||
|
self.on_commit_queue = []
|
||||||
|
|
||||||
def savepoint(self, message=None):
|
def savepoint(self, message=None):
|
||||||
savepoint_id = helpers.random_hex(length=16)
|
savepoint_id = helpers.random_hex(length=16)
|
||||||
|
|
Loading…
Reference in a new issue