Opened 15 years ago
Closed 10 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)
Change History (13)
by , 15 years ago
| Attachment: | 0001-XViewMiddleware-with-class-based-views.patch added | 
|---|
comment:1 by , 15 years ago
by , 15 years ago
| Attachment: | 0002-XViewMiddleware-with-class-based-views.patch added | 
|---|
I'm not sure know if this is a much better idea, but at least it works correctly.
comment:2 by , 15 years ago
| Cc: | added | 
|---|
comment:3 by , 15 years ago
| Owner: | changed from to | 
|---|---|
| Status: | new → assigned | 
| Triage Stage: | Unreviewed → Accepted | 
See #6735 too (adding class-based generic views to Django)
comment:4 by , 15 years ago
| Keywords: | class-based-views added | 
|---|---|
| milestone: | → 1.3 | 
comment:5 by , 15 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 , 15 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | assigned → closed | 
comment:7 by , 15 years ago
| Resolution: | fixed | 
|---|---|
| Status: | closed → reopened | 
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 , 14 years ago
| Severity: | → Normal | 
|---|---|
| Type: | → Bug | 
comment:9 by , 14 years ago
| Easy pickings: | unset | 
|---|---|
| milestone: | 1.3 | 
| Summary: | XViewMiddleware fails with class-based views → XViewMiddleware fails with django.contrib.syndication.views.Feed | 
| UI/UX: | unset | 
comment:10 by , 13 years ago
| Status: | reopened → new | 
|---|
comment:11 by , 10 years ago
| Resolution: | → fixed | 
|---|---|
| Status: | new → closed | 
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')
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.