Django

Code

Ticket #2745 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] make modpython error handler not barf on errors

Reported by: md@hudora.de Assigned to: adrian
Milestone: Component: Core framework
Version: SVN Keywords:
Cc: md@hudora.de Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I ran into situations where error handling broke because of mangeled errors resulting in ugly "Internal Server Error" messages(see below). It turned out that ModPythonRequest.__repr__() is used when reporting errors and ModPythonRequest.__repr__() relies in too much being sane to do it's job. The patch at http://c0re.23.nu/c0de/misc/django-3764-error_reporting_error.diff basically uses inelegat but effective try: [...] except: [...] blocks to avoid an error while error reporting.

Sampe Error:

Internal Server Error ...

[Sat Sep 16 12:14:51 2006] [error] [client 80.130.106.15] PythonHandler django.core.handlers.modpython: TemplateSyntaxError: Caught an exception while rendering: 'NoneType' object has no attribute 'split'

Original Traceback (most recent call last):
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/__init__.py", line 704, in render_node
    result = node.render(context)
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/defaulttags.py", line 189, in render
    value = bool_expr.resolve(context, True)
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/__init__.py", line 550, in resolve
    obj = resolve_variable(self.var, context)
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/template/__init__.py", line 655, in resolve_variable
    raise VariableDoesNotExist, "Failed lookup for key [%s] in %r" % (bits[0], current) # missing attribute
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/handlers/modpython.py", line 19, in __repr__
    return '<ModPythonRequest\
path:%s,\
GET:%s,\
POST:%s,\
COOKIES:%s,\
META:%s>' % \\
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/handlers/modpython.py", line 51, in _get_post
    self._load_post_and_files()
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/core/handlers/modpython.py", line 32, in _load_post_and_files
    self._post, self._files = http.parse_file_upload(self._req.headers_in, self.raw_post_data)
  File "/usr/local/lib/python2.4/site-packages/Django-0.95-py2.4.egg/django/http/__init__.py", line 56, in parse_file_upload
    name_dict = parse_header(submessage['Content-Disposition'])[1]
  File "/usr/local/lib/python2.4/cgi.py", line 331, in parse_header
    plist = map(lambda x: x.strip(), line.split(';'))
AttributeError: 'NoneType' object has no attribute 'split'
, referer: [...]

Attachments

django-3764-error_reporting_error.diff.txt (1.1 kB) - added by md@hudora.de on 09/16/06 05:42:31.

Change History

09/16/06 05:42:31 changed by md@hudora.de

  • attachment django-3764-error_reporting_error.diff.txt added.

09/25/06 02:25:12 changed by mtredinnick

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

(In [3820]) Fixed #2745 -- Made the repr methods for modpython and wsgi request more robust in the face of bad input, since they are needed for error handling. Based on a patch from md@hudora.de.

11/24/06 12:24:34 changed by ubernostrum

(In [4098]) 0.91-bugfixes: Backport [3820] to 0.91-bugfixes, refs #2745.

11/24/06 12:24:49 changed by ubernostrum

(In [4099]) 0.91-bugfixes: Backport [3820] to 0.91-bugfixes, refs #2745.


Add/Change #2745 ([patch] make modpython error handler not barf on errors)




Change Properties
Action