I am trying to make nested transaction.atomic()
work. The following block of code crashes when exiting first transaction.atomic()
with the following error MySQLdb._exceptions.OperationalError: (1305, 'SAVEPOINT s4568333760_x1 does not exist')
from django.contrib.auth.models import User
from django.test import TransactionTestCase
from django.db import transaction
class FooTest(TransactionTestCase):
def test_bar(self):
with transaction.atomic():
with transaction.atomic():
u = User.objects.create_user(username="abc", password="pass")
print("created user: {}".format(u.username))
It seems like this happens due to the fact that Django fails to execute TRANSACTION START
or SET AUTOCOMMIT=0
during the test. I know this by looking at local MySQL query log.
Of course, my final test is not that simple, but the following example shows the concept which should work by does not.
Am I doing something wrong or is this a bug of Django?