Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectattr and rejectattr require the third argument to be a collection #1227

Open
ccutrer opened this issue Dec 12, 2024 · 0 comments
Open

Comments

@ccutrer
Copy link
Contributor

ccutrer commented Dec 12, 2024

The following works in Jinja2:

>>> import jinja2
>>> env = jinja2.Environment()
>>> template = env.from_string("{{ [('action', 'down_single'), ('event_type', 'down_single')] | rejectattr(0, 'in', 'name,event_type') | list }}")
>>> template.render()
"[('action', 'down_single')]"

But with Jinjava, I get com.hubspot.jinjava.interpret.FatalTemplateErrorsException: Invalid argument in 'in': 1st argument with value 'name,event_type' must be iterable

I couldn't find the source in Jinja, but I presume somewhere it implicitly turns non-iterables into a list.

ccutrer added a commit to ccutrer/zigbee2mqtt that referenced this issue Dec 12, 2024
Jinjava (the Jinja implementation openHAB uses) has an issue with
a string as the third parameter to `rejectattr` (see HubSpot/jinjava#1227).
Passing a tuple works around the issue, and is still compatible with Home Assistant's
reference Python implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant