| 19 | |
| 20 | |
| 21 | {{{ |
| 22 | def 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 | |
| 33 | Ideally, 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 | |
| 35 | The 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. |