You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When argument value is None filters convert it to string 'None' then process it as string 'None'.
But if this behaviour was correct, the expression {{ if none == 'None' }} should return True. But returns False.
Also I didn't find any information about this behaviour in documentation: https://jinja.palletsprojects.com/en/3.1.x/templates/
code:
--test
{%- set value = none %}
value: {{ value }}
--now value is none and isn't string
check value is none: {{ true if value is none else false }}
check value is string: {{ true if value is string else false }}
--example with trim and length - none converts to string 'None'
value_trim: {{ value|trim }}
value_trim_length: {{ (value|trim)|length }}
check value_trim is none: {{ true if value|trim is none else false }}
check value_trim is string: {{ true if value|trim is string else false }}
--example with replace - none converts to string 'None'
replace_value: {{ value|replace('n','x') }}
check value_replace is none: {{ true if value|replace('n','x') is none else false }}
check value_replace is string: {{ true if value|replace('n','x') is string else false }}
--check if none == 'None'
check if none == 'None': {{ true if none == 'None' else false }}
compiled code:
--test
value: None
--now value is none and isn't string
check value is none: True
check value is string: False
--example with trim and length - none converts to string 'None'
value_trim: None
value_trim_length: 4
check value_trim is none: False
check value_trim is string: True
--example with replace - none converts to string 'None'
replace_value: Noxe
check value_replace is none: False
check value_replace is string: True
--check if none == 'None'
check if none == 'None': False
expected behavior:
It was expected that if the argument is None, then the filter like trim() will also return None.
Thank you.
Environment:
Python version: 3.10.11
Jinja version: 3.1.3
The text was updated successfully, but these errors were encountered:
I should note this appears to happen on filters that are specially geared towards strings. I'm not sure what you'd otherwise expect to happen when you ask to trim None but I'm confident multiple people would have differing opinions.
Many filters operate on strings, and convert their value to string to do so. None remains its own value in other operations. You wouldn't expect None == "None" in Python either, although you might expect some Python function to convert its argument to string. I don't see anything wrong here.
When argument value is
None
filters convert it to string'None'
then process it as string'None'
.But if this behaviour was correct, the expression
{{ if none == 'None' }}
should returnTrue
. But returnsFalse
.Also I didn't find any information about this behaviour in documentation:
https://jinja.palletsprojects.com/en/3.1.x/templates/
code:
compiled code:
expected behavior:
It was expected that if the argument is
None
, then the filter liketrim()
will also returnNone
.Thank you.
Environment:
The text was updated successfully, but these errors were encountered: