Opened 9 years ago

Closed 9 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: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


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/", line 277, in run
    self.result = application(self.environ, self.start_response)

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

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

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

  File "/usr/local/lib/python2.5/site-packages/django/views/", 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 9 years ago.
Same diff, but with PEP8 coding style

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by Rick.van.Hattem@…

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>

I recommend a wontfix.

comment:2 Changed 9 years ago by Luke Garner <dj-t@…>

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 Changed 9 years ago by Chris Beaven

Triage Stage: UnreviewedAccepted

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

comment:4 Changed 9 years ago by Thomas Güttler

Has patch: set

comment:5 Changed 9 years ago by Chris Beaven

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)

Changed 9 years ago by Thomas Güttler

Same diff, but with PEP8 coding style

comment:6 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

Fixed in [7065].

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