-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
'coroutine' object is not subscriptable in async template #1141
Comments
Please provide a minimal example, preferably without Quart since it's not directly related. cc @pgjones |
I'm not sure how to extract a MWE from our quart app (with all the models and nested structures defined etc), but it looks like the |
Start with a I can't do this for you because I don't know anything about your data. |
Also is the code snippet given the one that errors? I can't find |
@pgjones you are totally right, I took the wrong div from the file. added the div in the snippet |
Considering jinja spits out this:
I can only assume a change accidentally removed an await. Should be easy to find in the diffs. |
Oh god there was a black reformat between these two versions. |
Good spot, I missed the warning at the top, so used to looking at the bottom of tracebacks.
Will find the first commit that failed. It was probably me in #1101. :-( |
Disregard my earlier now deleted comments. I'm a tool. |
Actual minimal repro: {% for item in a.b[:1] %}{{ item }}{% endfor %} With this context: a = dict(b=[1, 2, 3]) Compiles to this incorrect code: from __future__ import division, generator_stop
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, identity, TemplateNotFound, Namespace, Undefined
from jinja2.asyncsupport import auto_await, auto_aiter, AsyncLoopContext
name = None
async def root(context, missing=missing, environment=environment):
resolve = context.resolve_or_missing
undefined = environment.undefined
cond_expr_undefined = Undefined
if 0: yield None
l_0_a = resolve('a')
pass
async for l_1_item in auto_aiter(await auto_await(environment.getattr((undefined(name='a') if l_0_a is missing else l_0_a), 'b'))[:1]):
pass
yield to_string(l_1_item)
l_1_item = missing
blocks = {}
debug_info = '1=13' |
Code produced in 2.10.3: from __future__ import division, generator_stop
from jinja2.runtime import LoopContext, TemplateReference, Macro, Markup, TemplateRuntimeError, missing, concat, escape, markup_join, unicode_join, to_string, identity, TemplateNotFound, Namespace
from jinja2.asyncsupport import auto_await, auto_aiter, make_async_loop_context
name = None
async def root(context, missing=missing, environment=environment):
resolve = context.resolve_or_missing
undefined = environment.undefined
if 0: yield None
l_0_a = resolve('a')
pass
async for l_1_item in auto_aiter(environment.getattr((undefined(name='a') if l_0_a is missing else l_0_a), 'b')[:1]):
pass
yield to_string(l_1_item)
l_1_item = missing
blocks = {}
debug_info = '1=12' |
Bug introduced in 4d0949b |
2.11.1 has been released. |
Expected Behavior
Rendering was succesfull with Jinja2 2.10.3
Actual Behavior
When upgrading from 2.10.3 to 2.11.0, our async Quart application breaks, HTTP ERROR 500 thrown at user.
Template Code
here, Candidate is a Quart Model which we loop over to show all Candidates in a Demand. I tried extracting the relevant part of the template:
simple.html
called in Quart via
quart.render_template
Full Traceback
Your Environment
The text was updated successfully, but these errors were encountered: