Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#29399 closed Bug (duplicate)

Template rendering errors are incorrectly blamed on base template

Reported by: oTree-org Owned by: nobody
Component: Template system Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Repro steps:

  • create a "base.html"
  • create a "child.html" that inherits from base.html with {% extends %}

put one of the following lines child.html:

{% url 'nonexistent' %}
{% include 'nonexistent.html' %}

Expected: the yellow error page's "template debug" context should highlight the offending line, as it does when you have a TemplateSyntaxError during compilation.

Actual: the error page incorrectly blames base.html, and says the error is at line 0:

"Error during template rendering
In template ...\base.html, error at line 0"

It then shows the first 10 lines of base.html, but of course there is no error there.

I think this is caused by django.template.base.Node.render_annotated, specifically this line:

e.template_debug = context.render_context.template.get_exception_info(e, self.token)

It seems fixed if I change it to:

e.template_debug = context.template.get_exception_info(e, self.token)

(I got the idea because I saw context.template referenced on the previous line.)

You can run the attached project which reproduces the issue (run server and open to /).

Attachments (1)

missing_template_vars.zip (12.8 KB) - added by oTree-org 3 years ago.

Download all attachments as: .zip

Change History (4)

Changed 3 years ago by oTree-org

Attachment: missing_template_vars.zip added

comment:1 Changed 3 years ago by oTree-org

I found this related bug: #27584.

It seems that if the line is written the other way, it conceals problems in the *parent* template.

Last edited 3 years ago by Tim Graham (previous) (diff)

comment:2 Changed 3 years ago by oTree-org

Furthermore, it seems that if template C extends B, which extends A, then errors in B will not be pinpointed correctly in either case (whether using context or context.render_context).

comment:3 Changed 3 years ago by Tim Graham

Resolution: duplicate
Status: newclosed

Duplicate of #28935.

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