Changes between Initial Version and Version 1 of Ticket #27974, comment 11


Ignore:
Timestamp:
Mar 31, 2017, 7:23:22 AM (7 years ago)
Author:
kapil garg

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27974, comment 11

    initial v1  
    1717                     template = context.template.engine.get_template(template_name)
    1818}}}
     19
     20
     21{{{
     22def test_include(self):
     23    engine = Engine(loaders=[
     24        ('django.template.loaders.locmem.Loader', {
     25            'template': '{% for x in vars %}{% include "include" %}{% include "include" %}{% endfor %}',
     26            'include': '{% ifchanged %}{{ x }}{% endifchanged %}',
     27        }),
     28    ])
     29    output = engine.render_to_string('template', dict(vars=[1, 1, 2, 2, 3, 3]))
     30    print(output)
     31}}}
     32
     33Ideally, the above code should produce "112233" but it produces "123" due to same state being used which can be resolved by applying the above patch ("self" instead of "self.context_key"). Same happens with "cycle" tag i.e. if there is cycle tag instead of ifchanged tag in included template, they will share same state causing undesired behaviour.
     34
     35The patches in previous comment and in this comment fix all these problems (nested caching and same state) . I can write more tests for these as well.
Back to Top