jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'cards'

See original GitHub issue

Hey @danielfrg !

Just tried flex for the first time. I was able to easily reproduce the Plotly example in the docs. However, when I tried applying it to an already existing notebook I got the following Jinja exception. Since you are the author of this tool, I think you can probably tell what went wrong here. Let me know if this is an easy fix as I was looking forward to applying this to an existing project, as a POC.

🚀🚀🚀

$ jupyter nbconvert --to flex eda.ipynb
[NbConvertApp] Converting notebook eda.ipynb to flex
Traceback (most recent call last):
  File "/opt/miniconda3/bin/jupyter-nbconvert", line 11, in <module>
    sys.exit(main())
  File "/opt/miniconda3/lib/python3.8/site-packages/jupyter_core/application.py", line 254, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/opt/miniconda3/lib/python3.8/site-packages/traitlets/config/application.py", line 845, in launch_instance
    app.start()
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 350, in start
    self.convert_notebooks()
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 524, in convert_notebooks
    self.convert_single_notebook(notebook_filename)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 489, in convert_single_notebook
    output, resources = self.export_single_notebook(notebook_filename, resources, input_buffer=input_buffer)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/nbconvertapp.py", line 418, in export_single_notebook
    output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/exporters/exporter.py", line 181, in from_filename
    return self.from_file(f, resources=resources, **kw)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/exporters/exporter.py", line 199, in from_file
    return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/exporters/html.py", line 119, in from_notebook_node
    return super().from_notebook_node(nb, resources, **kw)
  File "/opt/miniconda3/lib/python3.8/site-packages/nbconvert/exporters/templateexporter.py", line 384, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/opt/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/opt/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/opt/miniconda3/share/jupyter/nbconvert/templates/flex/index.html.j2", line 1, in top-level template code
    {%- import "flex.j2" as flex with context -%}
  File "/opt/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 1412, in make_module
    return TemplateModule(self, ctx)
  File "/opt/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 1542, in __init__
    body_stream = list(template.root_render_func(context))  # type: ignore
+  File "/opt/miniconda3/share/jupyter/nbconvert/templates/flex/flex.j2", line 238, in top-level template code
+    {%- set _ = vars.current_section["cards"].append(vars.current_card) -%}
  File "/opt/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 474, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'cards'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danielfrgcommented, Sep 18, 2021

I totally agree with you.

The idea is to been able to generate a dashboard with as little changes as possible to an existing notebook thats why its only adding a couple of markdown headers and tags to the cells.

I do considir this a bug and will take a look as soon as i can.

0reactions
danielfrgcommented, Sep 23, 2021

This is fixed now on 0.7.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

jinja2.exceptions.UndefinedError: 'dict object' has no attribute ...
Seems the inner dictionary inside the Jinja object is not being parsed correctly, but I cannot reproduce your bug on my computer.
Read more >
jinja2.exceptions.UndefinedError: 'dict object' has no attribute ...
Description Having just upgraded to 3002.2, we are seeing random instances where Pillar fails to render due to core grains (specifically ...
Read more >
In the video at 2:01, I get this error: jinja2.exceptions ...
exceptions.UndefinedError: 'function object' has no attribute 'get'. I have tried comparing my script with the script in the video some times.
Read more >
How to iterate over a list of values in a dict using jinja?
I have a dict with a list of values ...
Read more >
Lovelace_gen - Add abilities to ui_lovelace.yaml
jinja2.exceptions.UndefinedError: 'homeassistant.util.yaml.objects.NodeListClass object' has no attribute 'items'
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found