[Django] #25118: add template filter not work with forloop.counter

10 views
Skip to first unread message

Django

unread,
Jul 13, 2015, 7:28:15 AM7/13/15
to django-...@googlegroups.com
#25118: add template filter not work with forloop.counter
---------------------------------+--------------------
Reporter: dvinegla | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
{{{
{% with identifier="#id"|add:forloop.counter %}
{{ identifier }}
{% endwith %}
}}}

print empty value

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

Django

unread,
Jul 13, 2015, 1:47:15 PM7/13/15
to django-...@googlegroups.com
#25118: add template filter doesn't work with mixed types
--------------------------------------+------------------------------------
Reporter: dvinegla | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

The issue is that the `add` filter doesn't support mixed types (string and
integer in this case). It might be reasonable to add such support.

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

Django

unread,
Jul 16, 2015, 12:59:25 PM7/16/15
to django-...@googlegroups.com
#25118: add template filter doesn't work with mixed types
--------------------------------------+------------------------------------
Reporter: dvinegla | Owner: kswiat
Type: Cleanup/optimization | Status: assigned

Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* cc: konrad.swiat@… (added)
* owner: nobody => kswiat
* status: new => assigned


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

Django

unread,
Jul 16, 2015, 3:14:44 PM7/16/15
to django-...@googlegroups.com
#25118: add template filter doesn't work with mixed types
--------------------------------------+------------------------------------
Reporter: dvinegla | Owner: kswiat
Type: Cleanup/optimization | Status: assigned
Component: Template system | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by kswiat):

https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#add
{{{
This filter will first try to coerce both values to integers. If this
fails, it’ll attempt to add the values together anyway. This will work on
some data types (strings, list, etc.) and fail on others. If it fails, the
result will be an empty string.
}}}
References: #11687, #16676

The question is, how the `add` tag should behave. If adding fails, do we
expect the result to be concatenated string? Maybe we need separate tag to
do that?

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

Django

unread,
Jul 16, 2015, 3:37:06 PM7/16/15
to django-...@googlegroups.com
#25118: add template filter doesn't work with mixed types
--------------------------------------+------------------------------------
Reporter: dvinegla | Owner: kswiat
Type: Cleanup/optimization | Status: closed

Component: Template system | Version: 1.8
Severity: Normal | Resolution: wontfix

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

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

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


Comment:

I guess it's a "won't fix" based on the discussion in #16676 then. I don't
think Django needs to add a new filter for this case.

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

Django

unread,
Jul 16, 2015, 3:53:28 PM7/16/15
to django-...@googlegroups.com
#25118: add template filter doesn't work with mixed types
--------------------------------------+------------------------------------
Reporter: dvinegla | Owner: kswiat
Type: Cleanup/optimization | Status: closed
Component: Template system | Version: 1.8
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

Comment (by chadhs):

This seems to not be a bug. I did some simple tests to confirm the
behavior is consistent with the documentation.

The add filter correctly concats strings.
It also correctly coerces a string to an int adding allowing it to be
added to a subsequent int.
Two ints are also correctly added.
Lastly a string like my name fails to be coerced to an int and when added
to an int returns an empty value.

Once again, this is consistent with the docs. Thanks.

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

Reply all
Reply to author
Forward
0 new messages