Aubrey Stark-Toller
unread,Feb 8, 2016, 9:20:07 AM2/8/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
Hello,
When I override the AUTH_USER_MODEL setting to "auth.User", when
AUTH_USER_MODEL in settings is not set to "auth.User", in
either a TestCase or individual test, and then try to access the objects
attribute on the user model, I get an AttributeError.
The exact error I get is:
AttributeError: Manager isn't available; 'auth.User' has been swapped
for 'None'
I've found this to be the case in both Django 1.8 and 1.9.
This is easily reproducible in a fresh project : create a boilerplate
project with a boilerplate app, add a new user model (call it
CustomUser) to the app and set to AUTH_USER_MODEL to CustomUser, and add
the following test case to the app:
> from django.test import TestCase, override_settings
> from django.contrib.auth import get_user_model
>
> class MyTestCase(TestCase):
> @override_settings(AUTH_USER_MODEL = 'auth.User')
> def test_custom_user(self):
> UserModel = get_user_model()
> UserModel.objects.all()
get_user_model() retrieves the correct model but accessing objects
attribute gives the stated error when running the test.
If I throw in another user model (say CustomerUser2) and write a test
such as:
> @override_settings(AUTH_USER_MODEL = 'another_app.CustomerUser2')
> def test_custom_user(self):
> UserModel = get_user_model()
> UserModel.objects.all()
this works fine, and if I unset AUTH_USER_MODEL in settings again
everything works as expected.
Perhaps someone can shed some light on this behavior?
Cheers,
Aubrey