Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#16297 closed Bug (fixed)

unexpected behavior with make_list filter

Reported by: ned Owned by: teraom
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When using the make_list filter I would expect the following code to print 'foo' on the first iteration. But the conditional fails.

{% for i in 12345|make_list %}
{{i}}:
{% if 1 == i %}foo{% endif %}
{% endfor %}

Forcing the variable i to be an int with the following hack makes it work, but from reading the make_list documentation I thought it should already be an integer.

{% if 1 == i|add:0 %}foo{% endif %}

Am I missing something about the limitations of conditionals in the templating system?

Attachments (1)

make_list_integer-16297.diff (824 bytes) - added by teraom 4 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by julien

  • Component changed from Template system to Documentation
  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This is a bug in the documentation. make_list systematically casts the argument to a unicode string before creating the list:

>>> from django.template.defaultfilters import make_list
>>> make_list(12345)
[u'1', u'2', u'3', u'4', u'5']

comment:2 Changed 4 years ago by teraom

  • Has patch set
  • Owner changed from nobody to teraom
  • Status changed from new to assigned

Changed 4 years ago by teraom

comment:3 Changed 4 years ago by lrekucki

  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 4 years ago by DrMeers

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

In [16468]:

Fixed #16297 -- make_list documentation error regarding integers. Thanks ned and teraom.

comment:5 Changed 4 years ago by DrMeers

In [16469]:

[1.3.X] Fixed #16297 -- make_list documentation error regarding integers. Thanks ned and teraom.

Backport of r16468 from trunk.

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