Opened 4 years ago

Last modified 13 months ago

#13842 new Bug

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

Reported by: ch0wn Owned by: mk
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 4 years ago.
0002-XViewMiddleware-with-class-based-views.patch (1.1 KB) - added by ch0wn 4 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 (12)

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 4 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 4 years ago by ch0wn

  • Cc phartig@… added

comment:3 Changed 4 years ago by mk

  • Owner changed from nobody to mk
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 Changed 4 years ago by anonymous

  • Keywords class-based-views added
  • milestone set to 1.3

comment:5 Changed 4 years ago by russellm

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 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:7 Changed 3 years ago by lrekucki

  • Resolution fixed deleted
  • Status changed from closed to 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 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:9 Changed 3 years ago by ptone

  • Easy pickings unset
  • milestone 1.3 deleted
  • Summary changed from XViewMiddleware fails with class-based views to XViewMiddleware fails with django.contrib.syndication.views.Feed
  • UI/UX unset

comment:10 Changed 13 months ago by aaugustin

  • Status changed from reopened to new

Add Comment

Modify Ticket

Change Properties
<Author field>
as new
The owner will be changed from mk to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.