Opened 9 years ago

Closed 4 years ago

#13842 closed Bug (fixed)

XViewMiddleware fails with django.contrib.syndication.views.Feed

Reported by: ch0wn Owned by: Matthias Kestenholz
Component: Core (Other) Version: master
Severity: Normal Keywords: middleware class-based-views
Cc: phartig@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When doing a HEAD request on a class-based view, while having XViewMiddleware enabled, an error occures when accessing view_func.__name__, as an instance does not provide a __name__ attribute.


# mapped to /1
def simple_function(request):
    return HttpResponse("Hello World")

# mapped to /2
class SimpleClass(object):
    def __call__(self, request):
        return HttpResponse("Hello World")
» curl -I http://localhost:8000/1
HTTP/1.0 200 OK
Date: Sun, 27 Jun 2010 20:10:25 GMT
Server: WSGIServer/0.1 Python/2.6.5
X-View: djangoheadfix.views.simple_function
Content-Type: text/html; charset=utf-8

» curl -I http://localhost:8000/2
Date: Sun, 27 Jun 2010 20:10:56 GMT
Server: WSGIServer/0.1 Python/2.6.5
Content-Type: text/html

I'm going to attach a patch for this.

Attachments (2)

0001-XViewMiddleware-with-class-based-views.patch (1.1 KB) - added by ch0wn 9 years ago.
0002-XViewMiddleware-with-class-based-views.patch (1.1 KB) - added by ch0wn 9 years ago.
I'm not sure know if this is a much better idea, but at least it works correctly.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 9 years ago by Alex Gaynor

This patch almost certainly doesn't do what you want. Every single instance of a new style class, in all of python, has an __class__ attribute.

Changed 9 years ago by ch0wn

I'm not sure know if this is a much better idea, but at least it works correctly.

comment:2 Changed 9 years ago by ch0wn

Cc: phartig@… added

comment:3 Changed 9 years ago by Matthias Kestenholz

Owner: changed from nobody to Matthias Kestenholz
Status: newassigned
Triage Stage: UnreviewedAccepted

See #6735 too (adding class-based generic views to Django)

comment:4 Changed 9 years ago by anonymous

Keywords: class-based-views added
milestone: 1.3

comment:5 Changed 9 years ago by Russell Keith-Magee

The class-based views introduced by #6735 don't have this problem. I'll add some tests to confirm this for regression purposes.

comment:6 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: assignedclosed

(In [14269]) Fixed #13842 -- Added tests to verify that XViewMiddleware works with class-based views.

comment:7 Changed 9 years ago by Łukasz Rekucki

Resolution: fixed
Status: closedreopened

I'm going to reopen this, because it looks like django.contrib.syndication.views.Feed suffers from this erro (see this thread on django-users). So either we need to fix this or migrate syndication views to the new CBV framework.

comment:8 Changed 9 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:9 Changed 8 years ago by Preston Holmes

Easy pickings: unset
milestone: 1.3
Summary: XViewMiddleware fails with class-based viewsXViewMiddleware fails with django.contrib.syndication.views.Feed
UI/UX: unset

comment:10 Changed 7 years ago by Aymeric Augustin

Status: reopenednew

comment:11 Changed 4 years ago by Tim Graham

Resolution: fixed
Status: newclosed

I think the failure was caused by old style classes in Python 2.5. Seems to work based on this test:

>>> from django.contrib.syndication.views import Feed
>>> Feed = view_func
>>> view_func.__module__, view_func.__name__
('django.contrib.syndication.views', 'Feed')
Note: See TracTickets for help on using tickets.
Back to Top