`selectattr` and `rejectattr` require the third argument to be a collection

Open
#1,227 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java
Domain
backend

Research direction

Reproduce the issue with Jinjava using the provided template and compare its rejectattr/in behavior with Jinja2. Trace the argument handling for the in test and verify that the same string input is accepted as iterable, with the example rendering the expected filtered collection.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
785
Forks
184
Avg merge
6d 22h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from HubSpot/jinjava

All issues in HubSpot/jinjava

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.