summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Robenolt <matt@ydekproductions.com>2013-11-14 11:55:13 -0800
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-11-14 21:19:03 +0100
commit16e5fdd9cb8cca4d203b9255a9771b3c370e37d6 (patch)
tree63558ff9cdc39b412b050c73423a87d6e9a4a379
parent8d1f3396679c8bb446ad43b0727b45bdb77d87b4 (diff)
[1.5.x] Propagate get_user_model exception from get_user
Fixes #21439 Backport of 3560ef04 from master. Conflicts: django/contrib/auth/tests/auth_backends.py
-rw-r--r--django/contrib/auth/backends.py2
-rw-r--r--django/contrib/auth/tests/auth_backends.py24
2 files changed, 25 insertions, 1 deletions
diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py
index 6b31f72b03..aca270bbbd 100644
--- a/django/contrib/auth/backends.py
+++ b/django/contrib/auth/backends.py
@@ -62,8 +62,8 @@ class ModelBackend(object):
return False
def get_user(self, user_id):
+ UserModel = get_user_model()
try:
- UserModel = get_user_model()
return UserModel._default_manager.get(pk=user_id)
except UserModel.DoesNotExist:
return None
diff --git a/django/contrib/auth/tests/auth_backends.py b/django/contrib/auth/tests/auth_backends.py
index be29d9e78b..8da099566a 100644
--- a/django/contrib/auth/tests/auth_backends.py
+++ b/django/contrib/auth/tests/auth_backends.py
@@ -367,3 +367,27 @@ class InActiveUserBackendTest(TestCase):
def test_has_module_perms(self):
self.assertEqual(self.user1.has_module_perms("app1"), False)
self.assertEqual(self.user1.has_module_perms("app2"), False)
+
+
+@skipIfCustomUser
+class ImproperlyConfiguredUserModelTest(TestCase):
+ """
+ Tests that an exception from within get_user_model is propagated and doesn't
+ raise an UnboundLocalError.
+
+ Regression test for ticket #21439
+ """
+ def setUp(self):
+ self.user1 = User.objects.create_user('test', 'test@example.com', 'test')
+ self.client.login(
+ username='test',
+ password='test'
+ )
+
+ @override_settings(AUTH_USER_MODEL='thismodel.doesntexist')
+ def test_does_not_shadow_exception(self):
+ # Prepare a request object
+ request = HttpRequest()
+ request.session = self.client.session
+
+ self.assertRaises(ImproperlyConfigured, get_user, request)