[Django] #26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in templates.

7 views
Skip to first unread message

Django

unread,
Jul 2, 2016, 7:13:48 AM7/2/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
---------------------------------+--------------------
Reporter: flupzor | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
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'...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26830>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 2, 2016, 9:35:33 AM7/2/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
---------------------------------+--------------------------------------

Reporter: flupzor | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by flupzor):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:1>

Django

unread,
Jul 3, 2016, 6:15:38 AM7/3/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: assigned

Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergei-maertens):

* status: new => assigned
* owner: nobody => sergei-maertens


--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:2>

Django

unread,
Jul 3, 2016, 6:40:14 AM7/3/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sergei-maertens):

* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

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

The batch 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:3>

Django

unread,
Jul 15, 2016, 4:36:47 PM7/15/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Left some comments for improvement on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:4>

Django

unread,
Jul 16, 2016, 8:58:27 PM7/16/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:5>

Django

unread,
Aug 9, 2016, 8:47:42 AM8/9/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"31e053edfa01e47c26dfa03834beeba77e09403a" 31e053ed]:
{{{
#!CommitTicketReference repository=""
revision="31e053edfa01e47c26dfa03834beeba77e09403a"
Refs #26830 -- Added a test for a named cycle template tag inside an
ifchanged block and a for loop.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:6>

Django

unread,
Aug 9, 2016, 9:08:49 AM8/9/16
to django-...@googlegroups.com
#26830: Issue with combination of 'with', 'ifchanged' and 'cycle' templatetags in
templates.
-------------------------------------+-------------------------------------
Reporter: flupzor | Owner: sergei-
| maertens
Type: Bug | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"3ae3a1f9fad800d73892b14ac8a576e817a2da55" 3ae3a1f9]:
{{{
#!CommitTicketReference repository=""
revision="3ae3a1f9fad800d73892b14ac8a576e817a2da55"
Fixed #26830 -- Prevented the 'with' templatetag from resetting the cycle
variable to its initial state.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26830#comment:7>

Reply all
Reply to author
Forward
0 new messages