You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that context['numbers'] is an iterator, not an ordinary list. Once we’ve iterated through it once, its items are “used up” and so it acts like an empty list on subsequent iterations. I’d argue that this is a bug—rendering a Mustache template shouldn’t ever alter the context.
In the meantime, you can get around this bug by manually converting the iterator to a list. In the example above, using the line
(I tried to fix this by changing part of RenderEngine.fetch_section_data:
try:
iter(data)
exceptTypeError:
# Then the value does not support iteration.data= [data]
else:
ifis_string(data) orisinstance(data, dict):
# Do not treat strings and dicts (which are iterable) as lists.data= [data]
else:
# Otherwise, treat the value as a list. We call list() on it# in case it's a generator--if we didn't do this then iterating# through it once would "use up" all of the values and trying# to iterate a second time would produce nothing.data=list(data)
but that didn’t do it. I think the call to list() needs to be made somewhere earlier in the call stack.)
The text was updated successfully, but these errors were encountered:
Consider the following simple use of Pystache under Python 3:
The expected output is, modulo whitespace,
But the actual output is just
The problem is that
context['numbers']
is an iterator, not an ordinary list. Once we’ve iterated through it once, its items are “used up” and so it acts like an empty list on subsequent iterations. I’d argue that this is a bug—rendering a Mustache template shouldn’t ever alter the context.In the meantime, you can get around this bug by manually converting the iterator to a list. In the example above, using the line
gives the expected output.
(I tried to fix this by changing part of RenderEngine.fetch_section_data:
but that didn’t do it. I think the call to
list()
needs to be made somewhere earlier in the call stack.)The text was updated successfully, but these errors were encountered: