Opened 6 years ago

Closed 5 years ago

#14506 closed Bug (fixed)

Crash on HEAD request

Reported by: azurit Owned by: nobody
Component: Documentation Version: 1.2
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Alex Gaynor)

Traceback (most recent call last):

  File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 94, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)

  File "/usr/lib/python2.5/site-packages/django/middleware/doc.py", line 15, in process_view
    if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or (request.user.is_authenticated() and request.user.is_staff)):

AttributeError: 'WSGIRequest' object has no attribute 'user'

Attachments (2)

patch (806 bytes) - added by Klaas van Schelven 6 years ago.
Assert the right middleware is running similar to contrib.auth.middleware
docs (529 bytes) - added by Klaas van Schelven 6 years ago.
Added dependency description to the docs (I'm not too sure on the format, so please test first)

Download all attachments as: .zip

Change History (14)

comment:1 Changed 6 years ago by Alex Gaynor

Description: modified (diff)

Reformatted, please use the preview button in the future.

comment:2 Changed 6 years ago by pandres

Resolution: invalid
Status: newclosed

Please give us more information on how to reproduce. Also try a newer django version.

comment:3 Changed 6 years ago by Jannis Leidel

Looks like request.user is not set. Which means the Auth middleware was not successfully run.

comment:4 in reply to:  3 ; Changed 6 years ago by azurit

Replying to jezdez:

Looks like request.user is not set. Which means the Auth middleware was not successfully run.


Yes, Auth middleware is NOT loaded.

comment:5 Changed 6 years ago by azurit

Resolution: invalid
Status: closedreopened

comment:6 in reply to:  4 ; Changed 6 years ago by Karen Tracey

Replying to azurit:

Replying to jezdez:

Looks like request.user is not set. Which means the Auth middleware was not successfully run.


Yes, Auth middleware is NOT loaded.

If you don't have the auth middleware loaded, why do you have the XView middleware loaded (that's the code that is generating the exception)? That middleware is documented (http://docs.djangoproject.com/en/dev/ref/middleware/#django.middleware.doc.django.middleware.doc.XViewMiddleware) as providing some function for the admindocs feature, which is only accessible from admin, which requires the auth middleware to be in place. So XView assumes auth middleware is loaded.

Leaving open since I guess the XView code could handle this more gracefully, but the easiest fix would seem to be for you to remove it from your middleware setting.

comment:7 in reply to:  6 Changed 6 years ago by azurit

Replying to kmtracey:

Replying to azurit:

Replying to jezdez:

Looks like request.user is not set. Which means the Auth middleware was not successfully run.


Yes, Auth middleware is NOT loaded.

If you don't have the auth middleware loaded, why do you have the XView middleware loaded (that's the code that is generating the exception)? That middleware is documented (http://docs.djangoproject.com/en/dev/ref/middleware/#django.middleware.doc.django.middleware.doc.XViewMiddleware) as providing some function for the admindocs feature, which is only accessible from admin, which requires the auth middleware to be in place. So XView assumes auth middleware is loaded.

Leaving open since I guess the XView code could handle this more gracefully, but the easiest fix would seem to be for you to remove it from your middleware setting.


Thank you, i removed XView middleware. Maybe documentation should mention that XView depends on Auth ?

comment:8 Changed 6 years ago by Gabriel Hurley

Triage Stage: UnreviewedAccepted

Changed 6 years ago by Klaas van Schelven

Attachment: patch added

Assert the right middleware is running similar to contrib.auth.middleware

Changed 6 years ago by Klaas van Schelven

Attachment: docs added

Added dependency description to the docs (I'm not too sure on the format, so please test first)

comment:9 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:10 Changed 6 years ago by Thejaswi Puthraya

Component: UncategorizedDocumentation
Easy pickings: unset
UI/UX: unset

comment:11 Changed 6 years ago by Horst Gutmann <zerok@…>

Has patch: set
Triage Stage: AcceptedReady for checkin

Patch still applies cleanly to trunk.

comment:12 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: reopenedclosed

In [16496]:

Fixed #14506 -- Added an assertion to XViewMiddleware about the dependency on the authentication middleware. Thanks, vanschelven.

Note: See TracTickets for help on using tickets.
Back to Top