Skip to content

Instantly share code, notes, and snippets.

@k4ml
Created May 24, 2011 17:54
Show Gist options
  • Save k4ml/989248 to your computer and use it in GitHub Desktop.
Save k4ml/989248 to your computer and use it in GitHub Desktop.
Catch transaction before it being caught by transaction.commit_manually
def transact(func):
"""
Usage:
@transaction.commit_manually
@transact
def some_function(a, b):
do_something()
"""
def decorated(*args, **kwargs):
try:
func(*args, **kwargs)
except Exception, e:
print e
transaction.rollback()
sys.exit()
return decorated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment