From ef3734693277242e98996f591d9acf39e8819441 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 31 Mar 2014 08:10:59 -0400 Subject: [PATCH] [1.7.x] Fixed #22362 -- Improved AuthenticationMiddleware assertion message. Thanks Keryn Knight. Backport of 246face209 from master --- django/contrib/auth/middleware.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django/contrib/auth/middleware.py b/django/contrib/auth/middleware.py index 3ee742446d..31d42e13cf 100644 --- a/django/contrib/auth/middleware.py +++ b/django/contrib/auth/middleware.py @@ -13,8 +13,12 @@ def get_user(request): class AuthenticationMiddleware(object): def process_request(self, request): - assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'." - + assert hasattr(request, 'session'), ( + "The Django authentication middleware requires session middleware " + "to be installed. Edit your MIDDLEWARE_CLASSES setting to insert " + "'django.contrib.sessions.middleware.SessionMiddleware' before " + "'django.contrib.auth.middleware.AuthenticationMiddleware'." + ) request.user = SimpleLazyObject(lambda: get_user(request))