pallets / jinja

A very fast and expressive template engine.

Home Page:https://jinja.palletsprojects.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unique filter doesn't work when chain with map filter in async variant

nikierpan opened this issue · comments

Unique filter doesn't work when chain with map filter in async variant

Template that reproduces the bug:

{{ users | map(attribute="username", default="Anonymous") | unique | join(", ") }}

Render code:

text = await jinja2.Template(
       template, enable_async=True
).render_async()

Traceback:

File ".../lib/python3.11/site-packages/jinja2/environment.py", line 1321, in <listcomp>
    [n async for n in self.root_render_func(ctx)]  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<template>", line 4, in top-level template code
  File ".../lib/python3.11/site-packages/jinja2/async_utils.py", line 65, in auto_await
    return await t.cast("t.Awaitable[V]", value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/jinja2/filters.py", line 603, in do_join
    return sync_do_join(eval_ctx, await auto_to_list(value), d, attribute)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/jinja2/async_utils.py", line 84, in auto_to_list
    return [x async for x in auto_aiter(value)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/jinja2/async_utils.py", line 84, in <listcomp>
    return [x async for x in auto_aiter(value)]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../lib/python3.11/site-packages/jinja2/async_utils.py", line 77, in auto_aiter
    for item in t.cast("t.Iterable[V]", iterable):
  File ".../lib/python3.11/site-packages/jinja2/filters.py", line 437, in do_unique
    for item in value:
TypeError: 'async_generator' object is not iterable

Environment:

  • Python version: 3.11.5
  • Jinja version: 3.1.2