Created
February 15, 2014 14:47
-
-
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.
This file contains 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
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