mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
WIP: Check that union Jinja filter can be chained (#46298)
* Check that union Jinja filter can be chained
* set filters: fix unexpected templating type error
this error occurs with Jinja 2.10 since 32ec69d827,
for example when union filters are chained:
$ ansible all -i localhost, -mdebug -a"msg={{ []|union([])|union([]) }}"
localhost | FAILED! => {
"msg": "Unexpected templating type error occurred on ({{ []|union([])|union([]) }}):
unsupported operand type(s) for +: 'set' and 'list'"
}
This commit is contained in:
@@ -54,7 +54,12 @@ def unique(environment, a, case_sensitive=False, attribute=None):
|
||||
error = None
|
||||
try:
|
||||
if HAS_UNIQUE:
|
||||
c = set(do_unique(environment, a, case_sensitive=case_sensitive, attribute=attribute))
|
||||
c = do_unique(environment, a, case_sensitive=case_sensitive, attribute=attribute)
|
||||
if isinstance(a, collections.Hashable):
|
||||
c = set(c)
|
||||
else:
|
||||
c = list(c)
|
||||
|
||||
except Exception as e:
|
||||
if case_sensitive or attribute:
|
||||
raise AnsibleFilterError("Jinja2's unique filter failed and we cannot fall back to Ansible's version "
|
||||
|
||||
Reference in New Issue
Block a user