Opened 9 years ago

Closed 8 years ago

#6322 closed (fixed)

ifchanged doesn't properly reset itself if not evaluated each time through the loop

Reported by: nedbatchelder Owned by: nobody
Component: Template system Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

When using ifchanged in a doubly-nested loop, the value is only reset to None on the inner loop's first iteration. But if the ifchanged tag is inside another conditional, it may not be evaluated on the first iteration. This can mean the value isn't properly reset:

    {% for data in datalist %}
        {% for c,d in data %}
            {% if c %}
                {% ifchanged %}{{ d }}{% endifchanged %}
            {% endif %}
        {% endfor %}
    {% endfor %}

The fix is to not examine forloop.first explicitly, but to annotate the forloop context.

Attachments (1)

ifchanged.diff (2.3 KB) - added by nedbatchelder 9 years ago.
the patch!

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by nedbatchelder

the patch!

comment:1 Changed 8 years ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 8 years ago by adrian

  • Description modified (diff)

Fixed formatting in description.

comment:3 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [7752]) Fixed #6322 -- Fixed bug in 'ifchanged' template tag where it wasn't resetting itself properly in some cases. Thanks, nedbatchelder

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