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

Using namespaces asynchronously raises fatal AttributeError #1180

Closed
bartfeenstra opened this issue Mar 28, 2020 · 0 comments · Fixed by #1181
Closed

Using namespaces asynchronously raises fatal AttributeError #1180

bartfeenstra opened this issue Mar 28, 2020 · 0 comments · Fixed by #1181
Milestone

Comments

@bartfeenstra
Copy link
Contributor

@bartfeenstra bartfeenstra commented Mar 28, 2020

When asynchronously rendering templates that make use of namespaces, rendering fails on AttributeError: __class__.

Expected Behavior

No error is raised.

Actual Behavior

Using namespaces when rendering templates asynchronously fails on the isawaitable() check performed on Namespace.

Template Code

{% set ns = namespace(foo=[]) %}

Reproduction:

import asyncio

from jinja2 import Environment

async def main():
    environment = Environment(
        enable_async=True
    )
    template = '{% set ns = namespace(foo=[]) %}'
    await environment.from_string(template).render_async()

asyncio.get_event_loop().run_until_complete(main())

Full Traceback

Traceback (most recent call last):
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/utils.py", line 699, in __getattribute__
    return self.__attrs[name]
KeyError: '__class__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "namespace.py", line 12, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "namespace.py", line 10, in main
    await environment.from_string(template).render_async()
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 65, in render_async
    return self.environment.handle_exception()
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 25, in concat_async
    await collect()
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 22, in collect
    async for event in async_gen:
  File "<template>", line 1, in top-level template code
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/asyncsupport.py", line 173, in auto_await
    if inspect.isawaitable(value):
  File "/usr/lib/python3.8/inspect.py", line 234, in isawaitable
    isinstance(object, collections.abc.Awaitable))
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/abc.py", line 98, in __instancecheck__
    return _abc_instancecheck(cls, instance)
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/utils.py", line 701, in __getattribute__
    raise AttributeError(name)
AttributeError: __class__

Your Environment

  • Python version: Python 3.8
  • Jinja version: 2.11.1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants