Since I am using NDB for my projects, on Python 2.7 SDK, I cannot use Query().iter() normally with Jinja2 templates.
My usual code follows this pattern:
mc_key = ...
instances = memcache.get('instances-%s' % mc_key)
if not instances:
q_i = MyModel.query(...)
instances = q_i.iter()
if instances:
memcache.set('instances-%s' % mc_key, instances)
And then in Jinja2:
{% for i in instances %}
{{i.property1}}
{% endfor %}
This also happens when I call the QueryIterator object in the Python code. Adding to the previous Python code:
for i in instances:
# Do something with i
I always get a "deadlock waiting for <future created by XXX, pending>" when I loop the iterator.
A working walkaround is:
q_i = MyModel.query()
instances = q_i.iter()
if instances:
instances = list(instances)
Someone knows why that next() does not work as I expected? Some more elegant and/or efficient solution? Thank you in advance.