According to the documentation, when using attribute in map instead of a filter, if the value of attribute is not a key of an input element, default can be specified to supply a value instead. In the past, that would fail if that value could be cast to False (#1331). I have no idea if that is some sort of regression, or if None was never tested against.
This seems indeed to work for most of those values, except for None. I have no jinja executable and no idea how to invoke jinja, so here is an example with ansible, with an error message being identical as if default had not been specified at all, as seen in the last meaningful line:
./venv/latest/bin/ansible -m debug -a 'msg={{[{}]|map(attribute="foo",default=none)}}' localhost
[ERROR]: Task failed: Finalization of task args for 'ansible.builtin.debug' failed: Error while resolving value for 'msg': object of type 'dict' has no attribute 'foo'
Task failed.
Origin: <adhoc 'debug' task>
{'action': 'debug', 'args': {'msg': '{{[{}]|map(attribute="foo",default=none)}}'}, 'timeout': 0, 'async_val': 0, [...]
<<< caused by >>>
Finalization of task args for 'ansible.builtin.debug' failed.
Origin: <CLI option '-m'>
debug
<<< caused by >>>
Error while resolving value for 'msg': object of type 'dict' has no attribute 'foo'
Origin: <CLI option '-a'>
{{[{}]|map(attribute="foo",default=none)}}
localhost | FAILED! => {
"changed": false,
"msg": "Task failed: Finalization of task args for 'ansible.builtin.debug' failed: Error while resolving value for 'msg': object of type 'dict' has no attribute 'foo'"
}
Environment:
- Python version: 3.13.5
- Jinja version: 3.1.6
I believe this results from how prepare_map() handles kwargs.
According to the documentation, when using
attributeinmapinstead of a filter, if the value ofattributeis not a key of an input element,defaultcan be specified to supply a value instead. In the past, that would fail if that value could be cast toFalse(#1331). I have no idea if that is some sort of regression, or ifNonewas never tested against.This seems indeed to work for most of those values, except for
None. I have no jinja executable and no idea how to invoke jinja, so here is an example with ansible, with an error message being identical as ifdefaulthad not been specified at all, as seen in the last meaningful line:Environment:
I believe this results from how
prepare_map()handleskwargs.