Opened 5 years ago

Closed 5 years ago

Last modified 5 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 5 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by Julien Phalip

Component: Template systemDocumentation
Easy pickings: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

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 5 years ago by teraom

Has patch: set
Owner: changed from nobody to teraom
Status: newassigned

Changed 5 years ago by teraom

comment:3 Changed 5 years ago by Łukasz Rekucki

Triage Stage: AcceptedReady for checkin

comment:4 Changed 5 years ago by Simon Meers

Resolution: fixed
Status: assignedclosed

In [16468]:

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

comment:5 Changed 5 years ago by Simon Meers

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