Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#19949 closed Cleanup/optimization (fixed)

Cached template loader doesn't cache TemplateDoesNotExist — at Version 9

Reported by: German M. Bravo Owned by: Susan Tan
Component: Template system Version: 1.5
Severity: Normal Keywords: templates cache
Cc: German M. Bravo Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

In cases where multiple fallback templates are requested to the template loader (i.e. django.template.loader.select_template()) to find the first one available, the cached template loader does not cache non-existent templates, making cached loader "slow" again if every time it has to try looking for a template that's been already found to be missing.

from django.template.loader import render_to_string
render_to_string(['missing_template_1.html', 'missing_template_2.html', ..., 'missing_template_N.html', 'existent_template.html'])

When using django.template.loaders.cached.Loader, and given that snippet above, and the fact that missing_template_1.html ... missing_template_N.html do not exist, the filesystem loader or other loaders get hit every time (trying and trying to find already known as missing templates).

I'm attaching a patch to fix this.

Change History (10)

by German M. Bravo, 11 years ago

comment:1 by German M. Bravo, 11 years ago

Cc: German M. Bravo added

comment:2 by German M. Bravo, 11 years ago

Component: UncategorizedTemplate system
Has patch: set
Keywords: templates cache added
Type: UncategorizedCleanup/optimization

comment:3 by Jacob, 11 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Graham, 11 years ago

Needs tests: set

It would be good to add a test for this.

comment:5 by Susan Tan, 11 years ago

Updated PR: https://github.com/django/django/pull/1501/ Unit test and full test suite pass.

Last edited 11 years ago by Susan Tan (previous) (diff)

comment:6 by Tim Graham, 11 years ago

Needs tests: unset
Patch needs improvement: set

comment:7 by Susan Tan, 11 years ago

Owner: changed from nobody to Susan Tan
Status: newassigned

comment:8 by Tim Graham, 11 years ago

Patch needs improvement: unset
Resolution: fixed
Status: assignedclosed

comment:9 by Ramiro Morales, 11 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top