-
-
Notifications
You must be signed in to change notification settings - Fork 237
Description
Doing some testing of our Django 1.5.4 project to see if we can upgrade to Django 1.6, and I am running into this error when running unit tests:
TransactionManagementError: Your database backend doesn't behave properly when autocommit is off. Turn it on before using 'atomic'.
I am running django-nose 1.2, with a sqllite database for unit tests.
Digging into this, it seems like FastFixtureTestCase code is doing some direct transaction management, to save time on fixture loading(which is the point), but it does not seem compatible with Django 1.6's new transaction management.
From what I can see, the problem starts in my code with a "get_or_create", and then there is a atomic block that Django is trying to execute to resolve this, which throws the error because (I am assuming) FastFixtureTestCase has set transaction management to be enabled?
This is easy to duplicate, I setup a quick project which demonstrates the issue here:
https://github.com/fertringer/django-nose-possible-bug-1.6.git
You don't even need to add any fixtures (which we do have on the real tests), and the error will trigger when you run ./manage.py test
I'm going to try and mock out get_or_create but I'd rather not do that everywhere in my code base as it is quite large, and we use that function in several place, so any help would be appreciated.
edit:
More fundamentally it looks like an issue with any code inside an atomic block when using FastFixtureTestCase, even something like:
from django.db import transaction
@transaction.atomic
def function():
return TrueTesting this will trigger the same error.