﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
7299	XViewMiddleware raises AttributeError when authentication system is disabled	Takanori Ishikawa	nobody	"==== How to reproduce ====
 1. Disable {{{django.contrib.auth.middleware.AuthenticationMiddleware}}} in {{{settings.MIDDLEWARE_CLASSES}}}
 2. Disable {{{django.contrib.auth}}} in {{{settings.INSTALLED_APPS}}}
 3. Make sure {{{settings.INTERNAL_IPS}}} is empty.

{{{
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

INSTALLED_APPS = (
    #'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'mysite.polls',
)

INTERNAL_IPS = ()
}}}

 4. Open url via a HEAD request. (Make sure the corresponding page exists in {{{url.py}}})
 5. '500 INTERNAL SERVER ERROR' response 

{{{
% curl --head http://localhost:8000/polls/
HTTP/1.0 500 INTERNAL SERVER ERROR
Date: Fri, 23 May 2008 15:23:53 GMT
Server: WSGIServer/0.1 Python/2.5.2
Content-Type: text/html
}}}

 6. So, in the Python traceback, it caused by {{{django.middleware.doc.XViewMiddleware}}}

{{{
05-19 05:48AM 48.597 Exception in request: Traceback (most recent call
Exception in request:
Traceback (most recent call last):
  File ""/base/data/home/apps/metareal/1.10/django/core/handlers/base.py"", line 77, in get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File ""/base/data/home/apps/metareal/1.10/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'
}}}

==== My Environment ====

 * Mac OS X 10.4.11
 * Python 2.5.2
 * Django revision 7547


==== Patch ====

Attached patch: {{{django_xview_middleware.diff}}} might fix the problem. It also add testcase for XViewMiddleware.

"	Bug	closed	Core (Other)	dev	Normal	duplicate			Accepted	1	0	0	0	0	0
