Django

Code

Ticket #6423 (closed: fixed)

Opened 11 months ago

Last modified 10 months ago

technical_500_response fails on String Exceptions

Reported by: Luke Garner <dj-t@lunoho.com> Assigned to: nobody
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

views_debug_string_exceptions.diff (0.6 kB) - added by guettli on 01/24/08 03:10:35.
Same diff, but with PEP8 coding style

Change History

01/19/08 19:31:04 changed by Rick.van.Hattem@Fawo.nl

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

01/19/08 21:18:37 changed by Luke Garner <dj-t@lunoho.com>

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.

01/20/08 18:35:29 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

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

01/23/08 08:56:43 changed by guettli

  • has_patch set to 1.

01/23/08 12:36:03 changed by SmileyChris

  • 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)

01/24/08 03:10:35 changed by guettli

  • attachment views_debug_string_exceptions.diff added.

Same diff, but with PEP8 coding style

02/02/08 22:38:05 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [7065].


Add/Change #6423 (technical_500_response fails on String Exceptions)




Change Properties
Action