Opened 3 years ago

Last modified 4 months ago

#28935 assigned Bug

Template error raised in an {% extends %} child template shows incorrect source location on debug page

Reported by: Matt Westcott Owned by: Zahid Hussain Ansari
Component: Template system Version: master
Severity: Normal Keywords:
Cc: Preston Timmons, Collin Anderson, pascal chambon, Simone Lazzaris, Min ho Kim Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If an error occurs in the processing of a template tag on a template that extends another via {% extends %}, the "Error during template rendering" section of the debug page incorrectly shows an excerpt from the parent template rather than the child.

To reproduce:


{% block body %}{% endblock %}


{% extends "base.html" %}

{% block body %}
    {% include "does_not_exist" %}
{% endblock %}

from django.shortcuts import render

def home(request):
    return render(request, 'home.html')

The resulting error page displays:

Error during template rendering
In template /Users/matthew/Development/tbx/wagtail/debug/brokendebug/core/templates/base.html, error at line 0

1	{% block body %}{% endblock %}

instead of the expected error output:

Error during template rendering
In template /Users/matthew/Development/tbx/wagtail/debug/brokendebug/core/templates/home.html, error at line 4

1	{% extends "base.html" %}
3	{% block body %}
4	    {% include "does_not_exist" %}
5	{% endblock %}

Bisecting shows that this bug was introduced in #27956 (e643ba8bcf0b1da517cbab689ac157ee031202a3), which was a fix for the opposite case: an error occurring on the parent template. (In the above test case, moving the line {% include "does_not_exist" %} to base.html turns it into a test case for #27956, and fails on pre-e643ba8bcf0b1da517cbab689ac157ee031202a3 revisions as expected.)

Change History (17)

comment:1 Changed 3 years ago by Tim Graham

Cc: Preston Timmons added
Component: UncategorizedTemplate system
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:4 Changed 2 years ago by Collin Anderson

Cc: Collin Anderson added

comment:5 Changed 2 years ago by Ankur Jain

Owner: set to Ankur Jain
Status: newassigned

comment:6 Changed 2 years ago by Ankur Jain

When the parser runs then it appends all the child template nodes to the parent template nodes and hence when template not found error comes then it's reported from the parent html instead of the child html.

comment:7 Changed 2 years ago by Simon Charette

#29740 was a duplicate.

comment:8 in reply to:  6 Changed 17 months ago by Michael F. Lamb

Replying to Ankur Jain:
Hi, I'm interested in working on this bug. Are you still working on it, Ankur?

comment:9 Changed 15 months ago by pascal chambon

Cc: pascal chambon added

Error confirmed on Django2.2.1, it makes the debug page much less helpful in case of TemplateError, since most websites inherit their templates from some kind of "base.html" skeleton.

comment:10 Changed 13 months ago by Simone Lazzaris

Bug still present in 2.2.3; if you (like me) use a tree-structured number of small template files it is very VERY annoying as you have to guess where the bug you're chasing is between the various parts.

comment:11 Changed 13 months ago by Simone Lazzaris

Cc: Simone Lazzaris added
Version: 2.02.2

comment:12 Changed 13 months ago by felixxm

Owner: Ankur Jain deleted
Status: assignednew
Version: 2.2master

Simone, patch is welcome.

comment:13 Changed 11 months ago by Min ho Kim

Cc: Min ho Kim added

comment:14 Changed 11 months ago by Min ho Kim

Owner: set to Min ho Kim
Status: newassigned

comment:15 Changed 7 months ago by Min ho Kim

Owner: Min ho Kim deleted
Status: assignednew

I'm deassigning myself for now so someone else can have a go until I can come back in the future.

comment:16 Changed 6 months ago by Ashutosh Sharma

Owner: set to Ashutosh Sharma
Status: newassigned

comment:17 Changed 6 months ago by Ashutosh Sharma

Owner: Ashutosh Sharma deleted
Status: assignednew

I couldn't find a way to fix this bug. Deassigning so someone else can have a try.

comment:18 Changed 5 months ago by Zahid Hussain Ansari

Owner: set to Zahid Hussain Ansari
Status: newassigned

comment:19 Changed 4 months ago by felixxm

#31478 was a duplicate.

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