Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15502 closed (fixed)

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

Reported by: jaylett 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 jaylett 3 years ago.
Traceback of problem
15502-test.patch (2.2 KB) - added by jaylett 3 years ago.
Failing test
15502-test-and-fix.diff (3.1 KB) - added by GDorn 3 years ago.

Download all attachments as: .zip

Change History (10)

Changed 3 years ago by jaylett

Traceback of problem

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 3 years ago by jaylett

Failing test

comment:2 Changed 3 years ago by russellm

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

Changed 3 years ago by GDorn

comment:3 Changed 3 years ago by GDorn

  • 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 3 years ago by ramiro

  • Triage Stage changed from Accepted to Ready for checkin

comment:5 Changed 3 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

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 3 years ago by russellm

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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.