mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
This change:
* Makes the InclusionNode cache-safe by removing render-time side effects
to its nodelist.
* Ensures the render_context stack is properly scoped and reset by updating
the render call to use Template.render rather than Nodelist.render.
Backport of 0808ccce38 from master
This commit is contained in:
@@ -2,7 +2,8 @@ from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.template import Context, Template, TemplateSyntaxError
|
||||
from django.template import Context, Engine, Template, TemplateSyntaxError
|
||||
from django.template.base import Node
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.test.utils import extend_sys_path
|
||||
from django.utils import six
|
||||
@@ -274,6 +275,26 @@ class CustomTagTests(SimpleTestCase):
|
||||
c.use_l10n = True
|
||||
self.assertEqual(t.render(c).strip(), 'True')
|
||||
|
||||
def test_no_render_side_effect(self):
|
||||
"""
|
||||
#23441 -- InclusionNode shouldn't modify its nodelist at render time.
|
||||
"""
|
||||
engine = Engine(app_dirs=True)
|
||||
template = engine.from_string('{% load inclusion %}{% inclusion_no_params %}')
|
||||
count = template.nodelist.get_nodes_by_type(Node)
|
||||
template.render(Context({}))
|
||||
self.assertEqual(template.nodelist.get_nodes_by_type(Node), count)
|
||||
|
||||
def test_render_context_is_cleared(self):
|
||||
"""
|
||||
#24555 -- InclusionNode should push and pop the render_context stack
|
||||
when rendering. Otherwise, leftover values such as blocks from
|
||||
extending can interfere with subsequent rendering.
|
||||
"""
|
||||
engine = Engine(app_dirs=True)
|
||||
template = engine.from_string('{% load inclusion %}{% inclusion_extends1 %}{% inclusion_extends2 %}')
|
||||
self.assertEqual(template.render(Context({})).strip(), 'one\ntwo')
|
||||
|
||||
def test_assignment_tags(self):
|
||||
c = Context({'value': 42})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user