Opened 16 years ago

Closed 16 years ago

#6268 closed (duplicate)

Stacktraces caused by errors in response middleware look different than other errors

Reported by: eibaan Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I accidentally returned a number from a view. Obviously an error, but instead of the usual nice debug page, a black-on-white stacktrace is all that is returned. I'm using the development server and the SVN trunk version if that matters.

Traceback (most recent call last):
  File ".../python2.5/site-packages/django/core/servers/basehttp.py", line 277, in run
    self.result = application(self.environ, self.start_response)
  File ".../python2.5/site-packages/django/core/servers/basehttp.py", line 631, in __call__
    return self.application(environ, start_response)
  File ".../python2.5/site-packages/django/core/handlers/wsgi.py", line 209, in __call__
    response = middleware_method(request, response)
  File ".../python2.5/site-packages/django/middleware/common.py", line 90, in process_response
    if response.status_code == 404:
AttributeError: 'int' object has no attribute 'status_code'

It looks like that the request, view and exception middleware is protected by the usual technical_500_response handler (see base.py, BaseHandler.get_response()) but not the response middleware (see wsgi.py, WSGIHandler.call()) Is there a reason for this difference? Why can't the base handler also apply the response middleware (just before the return in line 101 in base.py)? Both modpython.py and wsgi.py seem to use the same chunk of code here which could moved to base.py.

Attachments (1)

ticket6268.patch (661 bytes ) - added by Jan Rademaker <j.rademaker@…> 16 years ago.
Make sure a view returns a HttpResponse object

Download all attachments as: .zip

Change History (3)

by Jan Rademaker <j.rademaker@…>, 16 years ago

Attachment: ticket6268.patch added

Make sure a view returns a HttpResponse object

comment:1 by Jan Rademaker <j.rademaker@…>, 16 years ago

The problem is (might be); are there any scenarios where a view returns a HttpResponse-like object instead of an actual HttpResponse object? If not, I think ticket6268.patch should be sufficient.

comment:2 by Karen Tracey <kmtracey@…>, 16 years ago

Resolution: duplicate
Status: newclosed

#6094 addresses the same issue, with I think a more comprehensive patch. If you could try that patch and provide feedback in #6094 as to whether it works for the specific case you encountered that would be helpful.

Note: See TracTickets for help on using tickets.
Back to Top