spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
451 stars 130 forks source link

'nbformat.notebooknode.NotebookNode object' has no attribute 'tags' #569

Closed aiqc closed 3 years ago

aiqc commented 3 years ago

I can locally build my documentation with make html.

However, when I upload it to readthedocs, my build fails. It has been working for half a year.

Notebook error:
UndefinedError in notebooks/api_high_level.ipynb:
'nbformat.notebooknode.NotebookNode object' has no attribute 'tags'

^ the word 'tags' does not appear in my raw ipynb, so nbconvert must be trying to access nbformat.notebooknode.NotebookNode.tags or like so {% block any_cell %} {% if 'Hard' in cell['metadata'].get('tags', []) %}

The JSON of the actual ipynb lints fine.

I tried upgrading nbsphinx to 0.8.5 up from 0.8.0, and sphinx to 4.0.2 up from 3.4.3

Here is the full error:

Running Sphinx v4.0.2
loading translations [en]... done
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 19 source files that are out of date
updating environment: [new config] 19 added, 0 changed, 0 removed
reading sources... [  5%] community
reading sources... [ 10%] compatibility
reading sources... [ 15%] index
reading sources... [ 21%] links
reading sources... [ 26%] mission
reading sources... [ 31%] notebooks/api_high_level

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/nbsphinx.py", line 1021, in parse
    rststring, resources = exporter.from_notebook_node(nb, resources)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/nbsphinx.py", line 840, in from_notebook_node
    nb, resources, **kw)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/nbconvert/exporters/templateexporter.py", line 384, in from_notebook_node
    output = self.template.render(nb=nb_copy, resources=resources)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 124, in top-level template code
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/rst/index.rst.j2", line 1, in top-level template code
    {%- extends 'display_priority.j2' -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/base/display_priority.j2", line 1, in top-level template code
    {%- extends 'base/null.j2' -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/base/null.j2", line 26, in top-level template code
    {%- block body -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/base/null.j2", line 29, in block 'body'
    {%- block body_loop -%}
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/base/null.j2", line 31, in block 'body_loop'
    {%- block any_cell scoped -%}
  File "<template>", line 17, in block 'any_cell'
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/share/jupyter/nbconvert/templates/base/null.j2", line 84, in block 'any_cell'
    {%- block markdowncell scoped-%} {%- endblock markdowncell -%}
  File "<template>", line 153, in block 'markdowncell'
jinja2.exceptions.UndefinedError: 'nbformat.notebooknode.NotebookNode object' has no attribute 'tags'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/cmd/build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 350, in build
    self.builder.build_update()
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 294, in build_update
    len(to_build))
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 306, in build
    updated_docnames = set(self.read())
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 413, in read
    self._read_serial(docnames)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 434, in _read_serial
    self.read_doc(docname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 474, in read_doc
    doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/io.py", line 188, in read_doc
    pub.publish()
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/docutils/core.py", line 218, in publish
    self.settings)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/sphinx/io.py", line 108, in read
    self.parse()
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/docutils/readers/__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "/home/docs/checkouts/readthedocs.org/user_builds/aiqc/envs/latest/lib/python3.7/site-packages/nbsphinx.py", line 1032, in parse
    str(e))
nbsphinx.NotebookError: UndefinedError in notebooks/api_high_level.ipynb:
'nbformat.notebooknode.NotebookNode object' has no attribute 'tags'
mgeier commented 3 years ago

This seems to be the same issue as #563.

Which Jinja2 version are you using?

aiqc commented 3 years ago

@mgeier Thank you for your help. This was indeed the root of the problem. I added a line for jinja2=2.11.2 to my ReadTheDocs-specific requirements.txt, and it builds clean now.

I apologize for not searching; was working too late as it was and pushed myself a bit further to get the docs uploaded. Didn't have my wits about me. Just wanted to document the error before sleep.

Please let me know if you want me to comment on any other repo to get eyes on this.