Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#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


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)

36-include-template_dirs-in-template-caching-hash.diff (1.2 KB ) - added by Chris Lamb 14 years ago.

Download all attachments as: .zip

Change History (6)

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

milestone: 1.3
Needs tests: set
Triage Stage: UnreviewedAccepted

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

Resolution: fixed
Status: newclosed

(In [13295]) Fixed #13573 -- Corrected problem with template caching when template directories are provided. Thanks to lamby for the report.

comment:3 by Alex Gaynor, 14 years ago

Calling hash() here seems like a really bad idea. I'm just waiting for someone to provide a collision...

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

(In [13299]) Refs #13573 -- Modified the key technique added in r13295 to be more robust against potential key collisions while keeping key names human-readable. Thanks to Alex for being finicky.

comment:5 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

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