Opened 8 years ago

Closed 8 years ago

#26830 closed Bug (fixed)

Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in templates.

Reported by: Alexander Schrijver Owned by: Sergei Maertens
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I ran into the issue where I do a named cycle in a ifchanged templatetag and depending if the given value changes cycle, or do not cycle. This works, however, if I put this in a 'with' statement, then it stops working.

I've created two unit tests to show this behavior.

https://github.com/flupzor/django/commit/4833c4ea5d0cbfd1e7d1689e1887772856f5aba2

This is the output of the tests.

$ ./runtests.py template_tests.syntax_tests.test_cycle.CycleTagTests
Testing against Django installed in '/home/alex/django-repo/django' with up to 8 processes
Creating test database for alias 'default'...
Creating test database for alias 'other'...
.......................F.
======================================================================
FAIL: test_cycle29 (template_tests.syntax_tests.test_cycle.CycleTagTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/alex/django-repo/django/test/utils.py", line 209, in inner
    return func(*args, **kwargs)
  File "/home/alex/django-repo/tests/template_tests/utils.py", line 61, in inner
    func(self)
  File "/home/alex/django-repo/tests/template_tests/syntax_tests/test_cycle.py", line 144, in test_cycle29
    self.assertEqual(output, 'bcabcabcccaa')
AssertionError: u'bcabcabcaaaa' != 'bcabcabcccaa'

----------------------------------------------------------------------
Ran 25 tests in 0.028s

FAILED (failures=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

Change History (7)

comment:1 by Alexander Schrijver, 8 years ago

I've added a PR to github with a fix for this issue. https://github.com/django/django/pull/6865

comment:2 by Sergei Maertens, 8 years ago

Owner: changed from nobody to Sergei Maertens
Status: newassigned

comment:3 by Sergei Maertens, 8 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

Confirmed bug, I could reproduce with a simple project and the tests cover it well.

The patch looks allright to me, although I'm not sure that the set_upward method should exist on the Context class, but I'll leave that to other people to decide.

Last edited 8 years ago by Sergei Maertens (previous) (diff)

comment:4 by Tim Graham, 8 years ago

Patch needs improvement: set

Left some comments for improvement on the PR.

comment:5 by Tim Graham, 8 years ago

Patch needs improvement: unset

comment:6 by Tim Graham <timograham@…>, 8 years ago

In 31e053ed:

Refs #26830 -- Added a test for a named cycle template tag inside an ifchanged block and a for loop.

comment:7 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 3ae3a1f9:

Fixed #26830 -- Prevented the 'with' templatetag from resetting the cycle variable to its initial state.

Note: See TracTickets for help on using tickets.
Back to Top