Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created February 15, 2014 14:47
Show Gist options
  • Save kezabelle/9020224 to your computer and use it in GitHub Desktop.
Save kezabelle/9020224 to your computer and use it in GitHub Desktop.
Regardless of what the function does, I want to roll back the changes it made to the database. I have no idea how.
def function(**kwargs):
Thing.objects.create(**kwargs)
Thing2.objects.get_or_create(**kwargs)
# desired usage:
transaction.let_the_objects_buildup()
try:
function(a=1, b=2, c=3)
finally:
# regardless of what it wanted to do (savepoints, atomic, whatever)
transaction.rollback_whatever_it_did()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment