Skip to content
Browse files

Fixed #14506 -- Added an assertion to XViewMiddleware about the depen…

…dency on the authentication middleware. Thanks, vanschelven.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c29e454 commit 43cb78fafde45fae9e057d29878c2ebf40aef873 @jezdez jezdez committed
Showing with 15 additions and 8 deletions.
  1. +4 −0 django/middleware/
  2. +1 −0 docs/ref/middleware.txt
  3. +10 −8 tests/regressiontests/utils/
4 django/middleware/
@@ -12,6 +12,10 @@ def process_view(self, request, view_func, view_args, view_kwargs):
indicating the view function. This is used by the documentation module
to lookup the view function for an arbitrary page.
+ assert hasattr(request, 'user'), (
+ "The XView middleware requires authentication middleware to be "
+ "installed. Edit your MIDDLEWARE_CLASSES setting to insert "
+ "'django.contrib.auth.middleware.AuthenticationMiddleware'.")
if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or
(request.user.is_active and request.user.is_staff)):
response = http.HttpResponse()
1 docs/ref/middleware.txt
@@ -80,6 +80,7 @@ View metadata middleware
Sends custom ``X-View`` HTTP headers to HEAD requests that come from IP
addresses defined in the :setting:`INTERNAL_IPS` setting. This is used by
Django's :doc:`automatic documentation system </ref/contrib/admin/admindocs>`.
+Depends on :class:`~django.contrib.auth.middleware.AuthenticationMiddleware`.
GZIP middleware
18 tests/regressiontests/utils/
@@ -1,24 +1,26 @@
from django.http import HttpResponse
-from django.middleware.doc import XViewMiddleware
from django.template import Template, Context
from django.template.response import TemplateResponse
from django.test import TestCase, RequestFactory
from django.utils.decorators import decorator_from_middleware
-xview_dec = decorator_from_middleware(XViewMiddleware)
+class ProcessViewMiddleware(object):
+ def process_view(self, request, view_func, view_args, view_kwargs):
+ pass
+process_view_dec = decorator_from_middleware(ProcessViewMiddleware)
-def xview(request):
+def process_view(request):
return HttpResponse()
-class ClassXView(object):
+class ClassProcessView(object):
def __call__(self, request):
return HttpResponse()
-class_xview = xview_dec(ClassXView())
+class_process_view = process_view_dec(ClassProcessView())
class FullMiddleware(object):
@@ -52,13 +54,13 @@ def test_process_view_middleware(self):
Test a middleware that implements process_view.
- xview(self.rf.get('/'))
+ process_view(self.rf.get('/'))
def test_callable_process_view_middleware(self):
Test a middleware that implements process_view, operating on a callable class.
- class_xview(self.rf.get('/'))
+ class_process_view(self.rf.get('/'))
def test_full_dec_normal(self):

0 comments on commit 43cb78f

Please sign in to comment.
Something went wrong with that request. Please try again.