Opened 14 years ago

Closed 14 years ago

Last modified 13 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: no UI/UX: no

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 14 years ago.
Traceback of problem
15502-test.patch (2.2 KB ) - added by James Aylett 14 years ago.
Failing test
15502-test-and-fix.diff (3.1 KB ) - added by Sam Thompson 14 years ago.

Download all attachments as: .zip

Change History (10)

by James Aylett, 14 years ago

Attachment: debug.txt added

Traceback of problem

comment:1 by Russell Keith-Magee, 14 years ago

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.

by James Aylett, 14 years ago

Attachment: 15502-test.patch added

Failing test

comment:2 by Russell Keith-Magee, 14 years ago

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

by Sam Thompson, 14 years ago

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

comment:3 by Sam Thompson, 14 years ago

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 by Ramiro Morales, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Russell Keith-Magee, 14 years ago

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 by Russell Keith-Magee, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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