Opened 12 years ago

Closed 12 years ago

#19819 closed Bug (fixed)

Django highlights incorrect lines for template errors

Reported by: michaelvantellingen@… Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

This issue is bugging me for a while now and after searching for existing tickets (and finding none) i've decided to create a ticket for it.

Basically Django highlights the wrong lines when a template error occurs. Sometimes it even highlights a seemingly random line in the parent template (when an error occurs in the template which is included).

I'll attach a screenshot with an example.

Attachments (1)

Screen Shot 2013-02-13 at 15.36.56.png (47.7 KB ) - added by michaelvantellingen@… 12 years ago.
Example

Download all attachments as: .zip

Change History (5)

by michaelvantellingen@…, 12 years ago

Example

comment:1 by michaelvantellingen@…, 12 years ago

Has patch: set

comment:2 by Aymeric Augustin, 12 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

The patch looks quite good, but it needs a bit of polish.

First, I suggest to redo the PR against master.

You must support Python 2.6+ and 3.2+. Specifically, use the syntax except TemplateSyntaxError as e: to catch exceptions.

To test an exception, there's assertRaisesRegexp. Since it was renamed in Python 3, you must use this slightly contrived syntax:

from django.utils import six

with six.assertRaisesRegex(self, TemplateSyntaxError, ...):
    # raise exception here

Finally, make sure the code is clean — there a suprious print statement and a stray newline in a docstring.

Thanks!

comment:3 by michaelvantellingen@…, 12 years ago

Thanks for the feedback! Here is a new PR against master. Tested it with python 2.6, 2.7 and 3.2:

https://github.com/django/django/pull/723

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 138de533ff677b470a1e7b4b6ff084a5b7a7444b:

Fixed #19819 - Improved template filter errors handling.

Wrap the Parser.compile_filter method call with a try/except and call the
newly added Parser.compile_filter_error(). Overwrite this method in the
DebugParser to throw the correct error.

Since this error was otherwise catched by the compile_function try/except
block the debugger highlighted the wrong line.

Note: See TracTickets for help on using tickets.
Back to Top