Last active
January 12, 2021 17:41
-
-
Save stuaxo/4eca59083b005a6cb58f7451be706918 to your computer and use it in GitHub Desktop.
Aborting transaction context manager.
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
""" | |
Aborting transaction context manager, useful for when prototyping on Django. | |
""" | |
from contextlib import contextmanager | |
from django.db import transaction | |
class AbortTransaction(Exception): | |
pass | |
@contextmanager | |
def aborting_transaction(): | |
try: | |
with transaction.atomic(): | |
yield | |
raise AbortTransaction() | |
except AbortTransaction: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment