Code

Opened 6 years ago

Closed 6 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:

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 guettli 6 years ago.
Same diff, but with PEP8 coding style

Download all attachments as: .zip

Change History (7)

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

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

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 Changed 6 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 6 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Accepted

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

comment:4 Changed 6 years ago by guettli

  • Has patch set

comment:5 Changed 6 years ago by SmileyChris

  • Triage Stage changed from Accepted to Ready 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 6 years ago by guettli

Same diff, but with PEP8 coding style

comment:6 Changed 6 years ago by mtredinnick

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

Fixed in [7065].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.