Opened 16 years ago

Closed 16 years ago

Last modified 7 years ago

#6423 closed (fixed)

technical_500_response fails on String Exceptions

Reported by: Luke Garner <dj-t@…> Owned by: nobody
Component: Template system Version: dev
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The formated 500 response pages you get with DEBUG = True will fail if the error that is raised is a string, instead of of subclass of python's Exception.

This view:

def raise_string_view(request):    
    raise 'String error!'
    return render_to_response('some_template.html', {})

will throw this exception:

Traceback (most recent call last):

  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 277, in run
    self.result = application(self.environ, self.start_response)

  File "/usr/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 631, in __call__
    return self.application(environ, start_response)

  File "/usr/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 205, in __call__
    response = self.get_response(request)

  File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py", line 116, in get_response
    return debug.technical_500_response(request, *sys.exc_info())

  File "/usr/local/lib/python2.5/site-packages/django/views/debug.py", line 77, in technical_500_response
    if issubclass(exc_type, TemplateDoesNotExist):

TypeError: issubclass() arg 1 must be a class

Attachments (1)

views_debug_string_exceptions.diff (654 bytes ) - added by Thomas Güttler 16 years ago.
Same diff, but with PEP8 coding style

Download all attachments as: .zip

Change History (9)

comment:1 by Rick.van.Hattem@…, 16 years ago

String Exceptions are deprecated according to PEP 317

If everything is working correctly Python should be showing a deprecation error here:

>>> raise 'spam'
__main__:1: DeprecationWarning: raising a string exception is deprecated
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
spam

I recommend a wontfix.

comment:2 by Luke Garner <dj-t@…>, 16 years ago

Yeah, that DeprecationWarning shows up in the server logs if you know to go looking for it, but the Traceback is very non-descriptive. I had to searching through the template system source to find out what was going on. If nothing else, we should improve the error message that is sent to the browser, so that developers know they have to get rid of their string-based exceptions.

comment:3 by Chris Beaven, 16 years ago

Triage Stage: UnreviewedAccepted

technical_500_response shouldn't fail if at all possible. The fix shouldn't be too difficult.

comment:4 by Thomas Güttler, 16 years ago

Has patch: set

comment:5 by Chris Beaven, 16 years ago

Triage Stage: AcceptedReady for checkin

Thanks for the patch, guettli.

I can't decide if a test is needed for this change (or where it would go exactly). The code is clear, so I'll promote it and let a committer decide.

(PS: Try to stick to PEP8 - you should have spaces between your assignment "=" in code)

by Thomas Güttler, 16 years ago

Same diff, but with PEP8 coding style

comment:6 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [7065].

comment:7 by Tim Graham <timograham@…>, 7 years ago

In 0205e04:

Removed ExceptionReporter support for string exceptions.

Reverted refs #6423 since raising string exceptions is prohibited
since Python 2.5.

comment:8 by Tim Graham <timograham@…>, 7 years ago

In bc95e6a:

[1.11.x] Removed ExceptionReporter support for string exceptions.

Reverted refs #6423 since raising string exceptions is prohibited
since Python 2.5.

Backport of 0205e04ce7a554a7b9b27b412288cc6a0e75e48f from master

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