TEMPLATE_DEBUG / TemplateSyntaxError handling doesn't play nice with Jinja2
|Reported by:||miracle2k||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Django's error 500 page code in views/debug.py probes exceptions for a source attribute, and if it exists, expects it to contain a 2-tuple pointing to the location where the error occurred.
Jinja2's TemplateSyntaxError also features a source attribute, but it instead contains the source string of the template.
As a result, when Jinja2 is used for templating and such an error occurs, Django breaks down while trying to build an error page for it. Instead, you get a simple WSGI strack trace for the new problem, rather than the actual template exception. The problem is this line:
origin, (start, end) = self.exc_value.source
I would argue that Django assumption that the existence of an attribute named source implies a specific protocol is flawed. It should either check for a specific class (though there are appear to be multiple), or at least make sure that it ignores values it can't handle.
Change History (10)
comment:1 Changed 8 years ago by
|Patch needs improvement:||unset|
comment:6 Changed 7 years ago by
|Status:||closed → reopened|
|Triage Stage:||Unreviewed → Accepted|