Opened 14 years ago

Closed 9 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: dev
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

Description

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.

Example

views.py

# 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
HTTP/1.0 500 INTERNAL SERVER ERROR
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 14 years ago.
0002-XViewMiddleware-with-class-based-views.patch (1.1 KB ) - added by ch0wn 14 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 by Alex Gaynor, 14 years ago

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.

by ch0wn, 14 years ago

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

comment:2 by ch0wn, 14 years ago

Cc: phartig@… added

comment:3 by Matthias Kestenholz, 14 years ago

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

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

comment:4 by anonymous, 14 years ago

Keywords: class-based-views added
milestone: 1.3

comment:5 by Russell Keith-Magee, 14 years ago

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 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

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

comment:7 by Łukasz Rekucki, 14 years ago

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 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:9 by Preston Holmes, 13 years ago

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 by Aymeric Augustin, 12 years ago

Status: reopenednew

comment:11 by Tim Graham, 9 years ago

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