Opened 7 years ago
Closed 3 years ago
#28935 closed Bug (fixed)
Template error raised in an {% extends %} child template shows incorrect source location on debug page
Reported by: | Matt Westcott | Owned by: | cammil |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Preston Timmons, Collin Anderson, pascal chambon, Simone Lazzaris, Min ho Kim, cammil | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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:
base.html:
{% block body %}{% endblock %}
home.html:
{% extends "base.html" %} {% block body %} {% include "does_not_exist" %} {% endblock %}
views.py:
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 does_not_exist 1 {% block body %}{% endblock %} 2
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 does_not_exist 1 {% extends "base.html" %} 2 3 {% block body %} 4 {% include "does_not_exist" %} 5 {% endblock %} 6
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 (24)
comment:1 by , 7 years ago
Cc: | added |
---|---|
Component: | Uncategorized → Template system |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:4 by , 7 years ago
Cc: | added |
---|
comment:5 by , 6 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
follow-up: 8 comment:6 by , 6 years ago
comment:8 by , 6 years ago
Replying to Ankur Jain:
Hi, I'm interested in working on this bug. Are you still working on it, Ankur?
comment:9 by , 5 years ago
Cc: | 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 by , 5 years ago
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 by , 5 years ago
Cc: | added |
---|---|
Version: | 2.0 → 2.2 |
comment:12 by , 5 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
Version: | 2.2 → master |
Simone, patch is welcome.
comment:13 by , 5 years ago
Cc: | added |
---|
comment:14 by , 5 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:15 by , 5 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
I'm deassigning myself for now so someone else can have a go until I can come back in the future.
comment:16 by , 5 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:17 by , 5 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
I couldn't find a way to fix this bug. Deassigning so someone else can have a try.
comment:18 by , 5 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:20 by , 4 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:21 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:22 by , 4 years ago
Think I have an idea how to fix this. Going to do some more testing to make sure.
comment:23 by , 4 years ago
I've created a PR: https://github.com/django/django/pull/14367
Does anyone have any comments or feedback?
comment:24 by , 4 years ago
Cc: | added |
---|---|
Has patch: | set |
comment:25 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
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.