#13573 closed (fixed)
Cached template loader can return incorrect template
| Reported by: | Chris Lamb | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | 1.2 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The cached.Loader's find_template method constructs a cache key based solely on the requested template name and does not include the template_dirs. This results in find_template returning the incorrect template where a template with the same template_name was previously loaded and cached from a different set of template_dirs. That is to say, the function is overly non-injective.
For example, the following snippets return the same Template. when they should return a different template for templates/foo/file.html and templates/bar/file.html respectfully:
from django.template import loader a = loader.find_template('file.html', ('templates/foo',)) b = loader.find_template('file.html', ('templates/bar',))
Patch attached.
Attachments (1)
Change History (6)
by , 15 years ago
| Attachment: | 36-include-template_dirs-in-template-caching-hash.diff added |
|---|
comment:1 by , 15 years ago
| milestone: | → 1.3 |
|---|---|
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 by , 15 years ago
Calling hash() here seems like a really bad idea. I'm just waiting for someone to provide a collision...
(In [13295]) Fixed #13573 -- Corrected problem with template caching when template directories are provided. Thanks to lamby for the report.