Problem with caching template loader

48 views
Skip to first unread message

Curtis Maloney

unread,
Jul 7, 2016, 11:01:09 PM7/7/16
to django-d...@googlegroups.com
Hey,

a client of mine was having a strange bug with the caching template
loader, which we've yet to identify, but as I was looking at the code, I
saw the following:

def load_template(self, template_name, template_dirs=None):
key = self.cache_key(template_name, template_dirs)
template_tuple = self.template_cache.get(key)
# A cached previous failure:
if template_tuple is TemplateDoesNotExist:
raise TemplateDoesNotExist
elif template_tuple is None:
template, origin = self.find_template(template_name,
template_dirs)
if not hasattr(template, 'render'):
try:
template = Template(template, origin,
template_name, self.engine)
except TemplateDoesNotExist:
# If compiling the template we found raises
TemplateDoesNotExist,
# back off to returning the source and display name
for the template
# we were asked to load. This allows for correct
identification (later)
# of the actual template that does not exist.
self.template_cache[key] = (template, origin)
self.template_cache[key] = (template, None)
return self.template_cache[key]


Now... in that "except" clause at the end, it updates the cache dict
with (template, origin).. only then to fall through to set it AGAIN
_immediately_.... with (template, None)

Surely this is wrong one way or the other?

--
Curtis

Preston Timmons

unread,
Jul 8, 2016, 12:04:47 AM7/8/16
to Django developers (Contributions to Django itself)
Yep, that looks wrong. Looks like it was added in this commit:


The test case could be improved also by checking the appropriate key is set.

Preston
Reply all
Reply to author
Forward
0 new messages