Created
February 19, 2014 17:15
-
-
Save florentx/9096677 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# Helper to check if the name is a valid identifier | |
_isidentifier = re.compile(r'[a-zA-Z_]\w*').match | |
@contextlib.contextmanager | |
def savepoint(cr, name, quiet=False): | |
assert _isidentifier(name) | |
cr.execute('SAVEPOINT "%s";' % name) | |
try: | |
yield | |
except Exception: | |
cr.execute('ROLLBACK TO "%s";' % name) | |
if not quiet: | |
raise | |
finally: | |
cr.execute('RELEASE "%s";' % name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment