Revision 2930
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/sql.py | ||
---|---|---|
354 | 354 |
savepoint = 'level_'+str(self._savepoint) |
355 | 355 |
self.run_query('SAVEPOINT '+savepoint, log_level=4) |
356 | 356 |
self._savepoint += 1 |
357 |
try: |
|
358 |
try: return_val = func() |
|
359 |
finally: |
|
360 |
self._savepoint -= 1 |
|
361 |
assert self._savepoint >= 0 |
|
357 |
try: return func() |
|
362 | 358 |
except: |
363 | 359 |
self.run_query('ROLLBACK TO SAVEPOINT '+savepoint, log_level=4) |
364 | 360 |
raise |
365 |
else: |
|
361 |
finally: |
|
362 |
# Always release savepoint, because after ROLLBACK TO SAVEPOINT, |
|
363 |
# "The savepoint remains valid and can be rolled back to again" |
|
364 |
# (http://www.postgresql.org/docs/8.3/static/sql-rollback-to.html). |
|
366 | 365 |
self.run_query('RELEASE SAVEPOINT '+savepoint, log_level=4) |
367 |
self.do_autocommit() |
|
368 |
return return_val |
|
366 |
|
|
367 |
self._savepoint -= 1 |
|
368 |
assert self._savepoint >= 0 |
|
369 |
|
|
370 |
self.do_autocommit() # OK to do this after ROLLBACK TO SAVEPOINT |
|
369 | 371 |
|
370 | 372 |
def do_autocommit(self): |
371 | 373 |
'''Autocommits if outside savepoint''' |
Also available in: Unified diff
sql.py: DbConn.with_savepoint(): Always release savepoint, because after ROLLBACK TO SAVEPOINT, "The savepoint remains valid and can be rolled back to again" (http://www.postgresql.org/docs/8.3/static/sql-rollback-to.html). Moved `self._savepoint -= 1` to the main try block's new finally block.