terminal-labs / lektor-jinja-content

Render Lektor content fields with Jinja2.
Other
11 stars 5 forks source link

Jinja rendering fail with: 'bool' object has no attribute 'iter_fields' #8

Closed ikus060 closed 6 years ago

ikus060 commented 6 years ago
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/dist-packages/lektor/admin/modules/serve.py", line 149, in serve_artifact
    return serve_up_artifact(path)
  File "/usr/local/lib/python2.7/dist-packages/lektor/admin/modules/serve.py", line 128, in serve_up_artifact
    artifact_name, filename = li.resolve_artifact('/' + path, pad)
  File "/usr/local/lib/python2.7/dist-packages/lektor/admin/webui.py", line 60, in resolve_artifact
    prog, _ = builder.build(source)
  File "/usr/local/lib/python2.7/dist-packages/lektor/builder.py", line 1081, in build
    source=source, prog=prog)
  File "/usr/local/lib/python2.7/dist-packages/lektor/pluginsystem.py", line 161, in emit
    rv[plugin.id] = handler(**kwargs)
  File "/home/ikus060/.cache/lektor/packages/a61b6c20bc4af8b097f5c5f4a043cec7/lektor_jinja_content.py", line 36, in on_before_build
    prog.source._data[field] = self.jinjaify(pad, prog.source, data, field)
  File "/home/ikus060/.cache/lektor/packages/a61b6c20bc4af8b097f5c5f4a043cec7/lektor_jinja_content.py", line 20, in jinjaify
    data = self.env.jinja_env.from_string(data).render(context)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 862, in from_string
    return cls.from_code(self, self.compile(source), globals, None)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 553, in compile
    source = optimize(source, self)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/optimizer.py", line 27, in optimize
    return optimizer.visit(node)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/visitor.py", line 39, in visit
    return self.generic_visit(node, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jinja2/visitor.py", line 59, in generic_visit
    for field, old_value in node.iter_fields():
AttributeError: 'bool' object has no attribute 'iter_fields'

I've debug this one a bit. Since thiis plugin is converting every single fields it's not working of the content of the field is not a string. Thus it's failing on my side, because the field _discoverable is a bool and jinja is failing to process the data.

I'm not sure how to work around this one without changing the implementation to process only the body field or a fixed list of fields.

ikus060 commented 6 years ago

Closing, I was using version 0.2 on python2.7. I've upgrade to version 0.3 on python3