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

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

Closed
nikierpan opened this issue Sep 1, 2023 · 1 comment
Closed

Comments

@nikierpan
Copy link

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
@nikierpan
Copy link
Author

##1781

@davidism davidism closed this as completed Sep 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants