Skip to content

Rendering the 404 page causes AttributeError: 'Sphinx' object has no attribute 'get_target_uri' #148

@greyli

Description

@greyli

Hi, I tried to add sphinx-notfound-page (Version 0.6 or master) for Flask (with Pallets Sphinx Themes).

with the following conf:

extensions = [
    # ...
    'notfound.extension',
]
notfound_template = '404.html'
notfound_urls_prefix = None

then the build failed:

Running Sphinx v3.5.4
loading translations [en]... done
making output directory... done
...
generating indices... genindex py-modindex done

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/html/__init__.py", line 1054, in handle_page
    output = self.templates.render(templatename, ctx)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/readthedocs_ext/readthedocs.py", line 185, in rtd_render
    content = old_render(template, render_context)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/jinja2glue.py", line 192, in render
    return self.environment.get_template(template).render(context)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/jinja2/environment.py", line 1127, in render
    self.environment.handle_exception()
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/jinja2/environment.py", line 814, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/pallets_sphinx_themes/themes/pocoo/404.html", line 3, in top-level template code
    {% set title = _('Page Not Found') %}
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/pallets_sphinx_themes/themes/pocoo/layout.html", line 22, in top-level template code
    {% set version_warning = current_version.banner() if current_version %}
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/jinja2/sandbox.py", line 382, in call
    return __context.call(__obj, *args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/pallets_sphinx_themes/versions.py", line 156, in banner
    ).format(latest=latest.name, href=latest.href(context))
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/pallets_sphinx_themes/versions.py", line 134, in href
    path = builder.get_target_uri(pagename)
AttributeError: 'Sphinx' object has no attribute 'get_target_uri'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/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/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/application.py", line 352, in build
    self.builder.build_update()
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 298, in build_update
    len(to_build))
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 363, in build
    self.finish()
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/html/__init__.py", line 622, in finish
    self.finish_tasks.add_task(self.gen_pages_from_extensions)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/util/parallel.py", line 49, in add_task
    res = task_func()
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/html/__init__.py", line 646, in gen_pages_from_extensions
    self.handle_page(pagename, context, template)
  File "/home/docs/checkouts/readthedocs.org/user_builds/flaskx/envs/fix-docs-404/lib/python3.7/site-packages/sphinx/builders/html/__init__.py", line 1062, in handle_page
    (pagename, exc)) from exc
sphinx.errors.ThemeError: An error happened in rendering the page 404.
Reason: AttributeError("'Sphinx' object has no attribute 'get_target_uri'")

Theme error:
An error happened in rendering the page 404.
Reason: AttributeError("'Sphinx' object has no attribute 'get_target_uri'")

Full build log: https://readthedocs.org/projects/flaskx/builds/13534094/

The error related to this line in Pallets Sphinx Theme. I'm not quite sure if it's an issue of sphinx-notfound-page since I'm not very familiar with Sphinx, any thoughts will be helpful. Thanks!

Related issue: pallets/pallets-sphinx-themes#34

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions