From 5080311998a8ecc5b3f9fa162c19e55b70aa9f85 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Mon, 25 Mar 2013 09:10:32 +0100 Subject: [PATCH] Fixed #20130 -- Regression in {% cache %} template tag. --- django/templatetags/cache.py | 2 +- tests/template_tests/tests.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/templatetags/cache.py b/django/templatetags/cache.py index 8c061ca4c6..215f1179dc 100644 --- a/django/templatetags/cache.py +++ b/django/templatetags/cache.py @@ -59,5 +59,5 @@ def do_cache(parser, token): raise TemplateSyntaxError("'%r' tag requires at least 2 arguments." % tokens[0]) return CacheNode(nodelist, parser.compile_filter(tokens[1]), - parser.compile_filter(tokens[2]), + tokens[2], # fragment_name can't be a variable. [parser.compile_filter(token) for token in tokens[3:]]) diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 46d1f921e2..a9db9edc2f 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -441,6 +441,11 @@ class Templates(TestCase): output1 = template.render(Context({'foo': range(3), 'get_value': lambda: next(gen1)})) self.assertEqual(output1, '[0,1,2,3]', 'Expected [0,1,2,3] in first template, got {0}'.format(output1)) + def test_cache_regression_20130(self): + t = Template('{% load cache %}{% cache 1 regression_20130 %}foo{% endcache %}') + cachenode = t.nodelist[1] + self.assertEqual(cachenode.fragment_name, 'regression_20130') + def test_ifchanged_render_once(self): """ Test for ticket #19890. The content of ifchanged template tag was rendered twice."""