#10216 - TEMPLATE_DEBUG / TemplateSyntaxError handling doesn't play nice with Jinja2

12 views
Skip to first unread message

Armin Ronacher

unread,
Feb 6, 2010, 9:32:36 PM2/6/10
to Django developers
Hello everybody,

I would love to propose a new solution for ticket #10216 which is
currently a wontfix. Basically the problem is that with TEMPLATE_DEBUG
turned on, Django expects a certain protocol from exceptions catched
by the debugging system:

Either an exception does not have a .source attribute, or it has one
and this is a tuple that can be unpacked where one of the items is an
template loader origin and the second is the position in the template,
as far as I can see that.

Now the direct problem for me is that people get no proper debug
output in Django if Jinja 2 raise an exception, because the .source
attribute of a Jinja 2 exception has a different protocol: it's a
string. Of course I can work around that problem in Jinja and tell
people to disable TEMPLATE_DEBUG, but I think the issue is not limited
to Jinja 2.

The purpose of a debugging middleware is to show what went wrong.
Currently the debugging middleware does the opposite if you have any
exception with a source attribute that is not a template origin and
position information.

A quick search on google code showed me that .source is not an
uncommon attribute on exceptions. For example PyXML uses it in the
xpath for SyntaxException and internal exceptions. If any of these
would be raised in a django application, the user would experience a
broken debug view. Not sure how common PyQwt is in web applications
but that would have the same problem ;)

I would like to propose a different solution: do an instance check
against a django TemplateSyntaxError (or any other template exception
that has these .source attributes). That should be easy to accomplish
and the debug system already has a dependency on the template engine
anyways for the rendering of the UI.


Regards,
Armin

Jacob Kaplan-Moss

unread,
Feb 7, 2010, 10:24:53 AM2/7/10
to django-d...@googlegroups.com
On Sat, Feb 6, 2010 at 8:32 PM, Armin Ronacher
<armin.r...@active-4.com> wrote:
> I would like to propose a different solution: do an instance check
> against a django TemplateSyntaxError (or any other template exception
> that has these .source attributes). That should be easy to accomplish
> and the debug system already has a dependency on the template engine
> anyways for the rendering of the UI.

This sounds fine to me. Can you reopen the ticket and/or provide a patch?

Jacob

Reply all
Reply to author
Forward
0 new messages