id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 16676,The 'add' filter should stringify value or argument if the other value is a string,dtrebbien,Aymeric Augustin,"The 1.3 documentation for the `add` filter states: > 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. When the value and argument represent the second case (""If this fails, it'll attempt to add the values together anyway."") and one is a string while the other is a number, the result of the `add` filter is simply the value. Similar to the fix for ticket #393, I think that for this second case and if either value or argument to the filter is a string, the other value should be stringified. === Test cases === {{{ {{ 'test'|add:2 }} }}} Result is: `test` \\ Expected result: `test2` {{{ {{ 2|add:'test' }} }}} Result is: `2` \\ Expected result: `2test` === Workarounds === For the first test case, one workaround is to use a `{% with %}` tag: {{{ {% with 2|stringformat:'d' as arg_as_str %} {{ 'test'|add:arg_as_str }} {% endwith %} }}} For the second test case, the `stringformat` filter can be used to convert the number to a string before `add` is applied: {{{ {{ 2|stringformat:'d'|add:'test' }} }}} === Related tickets === * Ticket #393 [patch] Filters don't take the str() value of a var * Ticket #8088 Template system improvement: ""cat"" filter, ""include"" tag with filters * Ticket #11687 The 'add' template filter only works for integers, and can fail noisily ",Bug,closed,Template system,1.3,Normal,fixed,,dtrebbien@…,Ready for checkin,1,0,0,0,0,0