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

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

Using namespaces asynchronously raises fatal AttributeError #1180

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


Copy link

@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=[]) %}


import asyncio

from jinja2 import Environment

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


Full Traceback

Traceback (most recent call last):
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", 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 "", line 12, in <module>
  File "/usr/lib/python3.8/asyncio/", line 616, in run_until_complete
    return future.result()
  File "", 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/", line 65, in render_async
    return self.environment.handle_exception()
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", line 832, in handle_exception
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", line 28, in reraise
    raise value.with_traceback(tb)
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", line 25, in concat_async
    await collect()
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", 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/", line 173, in auto_await
    if inspect.isawaitable(value):
  File "/usr/lib/python3.8/", line 234, in isawaitable
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/", line 98, in __instancecheck__
    return _abc_instancecheck(cls, instance)
  File "/home/bart/tmp/jinja2-async-namespacce/venv/lib/python3.8/site-packages/jinja2/", 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.
None yet
None yet

Successfully merging a pull request may close this issue.

2 participants