Skip to content

Instantly share code, notes, and snippets.

@matagus
Created July 11, 2012 15:15
Show Gist options
  • Save matagus/3091068 to your computer and use it in GitHub Desktop.
Save matagus/3091068 to your computer and use it in GitHub Desktop.
django transactions
from django.db import transaction
def manual_rollback():
"""Create and rollback using manual transaction calls"""
transaction.enter_transaction_management()
transaction.managed()
try:
try:
create()
error()
except:
transaction.rollback()
else:
transaction.commit()
finally:
transaction.leave_transaction_management()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment