Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#15502 closed (fixed)

TemplateDoesNotExist reports incorrect template during {% include %} from Class Based Views / TemplateResponse objects

Reported by: James Aylett Owned by: nobody
Component: Template system Version: 1.3-beta
Severity: Keywords:
Cc: georgedorn@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If I have a django.views.generic.base.TemplateView as so:

from django.views.generic.base import TemplateView

class FailingView(TemplateView):
    template_name = 'outer.html'

with templates/outer.html being:

{% include "inner.html" %}

and templates/inner.html not existing, then the exception is:

TemplateDoesNotExist at /search/
outer.html

when it should be:

TemplateDoesNotExist at /search/
inner.html

This appears to be similar to #12787, but a test case similar to test_extends_include_missing_baseloader does not show up the problem, apparently because loader.get_template() will raise the correct exception, but loader.select_template() is used with a list or tuple inside SimpleTemplateResponse.resolve_template(), and gets this wrong.

Attachments (3)

debug.txt (2.5 KB) - added by James Aylett 6 years ago.
Traceback of problem
15502-test.patch (2.2 KB) - added by James Aylett 6 years ago.
Failing test
15502-test-and-fix.diff (3.1 KB) - added by Sam Thompson 6 years ago.

Download all attachments as: .zip

Change History (10)

Changed 6 years ago by James Aylett

Attachment: debug.txt added

Traceback of problem

comment:1 Changed 6 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

Valid problem, but not class-based view specific. As you've identified, the issue is with select_template(), which consumes the TemplateDoesNotExist error generated by the non-existence of inner.html, interprets that consumption as non-existence of the overall template, and then raises a new TemplateDoesNotExist exception because the list of provided template name (i.e., [outer.html]) couldn't be loaded.

Changed 6 years ago by James Aylett

Attachment: 15502-test.patch added

Failing test

comment:2 Changed 6 years ago by Russell Keith-Magee

#15510 is a duplicate, with a fairly complete analysis.

Changed 6 years ago by Sam Thompson

Attachment: 15502-test-and-fix.diff added

comment:3 Changed 6 years ago by Sam Thompson

Cc: georgedorn@… added
Has patch: set

Fix added; fixed the test as well, which raised an exception due to r not being set when everything else was working great.

Also, I just realized I re-implemented the solution from #15510; but now we have a working test and a working patch in the same place at the same time.

comment:4 Changed 6 years ago by Ramiro Morales

Triage Stage: AcceptedReady for checkin

comment:5 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

In [15717]:

Fixed #15502 -- Ensure that nested TemplateDoesNotExist errors are propegated with a meaningful error message when loaded using select_template. Thanks to jaylett for the report, and GDorn for the patch.

comment:6 Changed 6 years ago by Russell Keith-Magee

In [15718]:

[1.2.X] Fixed #15502 -- Ensure that nested TemplateDoesNotExist errors are propegated with a meaningful error message when loaded using select_template. Thanks to jaylett for the report, and GDorn for the patch.

Backport of r15717 from trunk.

comment:7 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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