Sphinx: Traceback when running sphinx-build because SuppressWarning can use Sphinx.config before it's set

Created on 17 May 2017  ·  3Comments  ·  Source: sphinx-doc/sphinx

Linked to #3267

Problem

If conf.py creates a Warning (usually as a side effect from whatever conf.py does), then when the Config() object is instanciated (and just before it's attached to the Sphinx object) the warning is fired. Problem is, it's then filtered by the SuppressWarning filter that will try to access self.app.config. At this point, config is not set. Sphinx crashes.

Procedure to reproduce the problem

$ mkdir test-sphinx
$ cd test-sphinx
$ mktmpenv
$ pip install sphinx==1.6.1
$ sphinx-quickstart
$ # Default answer to everything
$ echo "import logging\nlogging.warn('yay')" >> conf.py
$ make html
Running Sphinx v1.6.1

Exception occurred:
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/util/logging.py", line 309, in filter
    if is_suppressed_warning(type, subtype, self.app.config.suppress_warnings):
AttributeError: 'Sphinx' object has no attribute 'config'
The full traceback has been saved in /tmp/sphinx-err-9G7SMg.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Makefile:20 : la recette pour la cible « html » a échouée
make: *** [html] Erreur 1

Error logs / results

$ cat /tmp/sphinx-err-9G7SMg.log
# Sphinx version: 1.6.1
# Python version: 2.7.13 (CPython)
# Docutils version: 0.13.1 release
# Jinja2 version: 2.9.6
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/cmdline.py", line 305, in main
    opts.warningiserror, opts.tags, opts.verbosity, opts.jobs)
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/application.py", line 167, in __init__
    confoverrides or {}, self.tags)
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/config.py", line 150, in __init__
    execfile_(filename, config)
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/util/pycompat.py", line 150, in execfile_
    exec_(code, _globals)
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/six.py", line 699, in exec_
    exec("""exec _code_ in _globs_, _locs_""")
  File "<string>", line 1, in <module>
  File "conf.py", line 156, in <module>
    logging.warn("yay")
  File "/usr/lib/python2.7/logging/__init__.py", line 1619, in warning
    root.warning(msg, *args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1179, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1286, in _log
    self.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1296, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1336, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 755, in handle
    rv = self.filter(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 617, in filter
    if not f.filter(record):
  File "/home/joachim/.virtualenvs/envs/test-sphinx/local/lib/python2.7/site-packages/sphinx/util/logging.py", line 309, in filter
    if is_suppressed_warning(type, subtype, self.app.config.suppress_warnings):
AttributeError: 'Sphinx' object has no attribute 'config'

Expected results

Should work

Reproducible project / your project

All commands necessary are in the previous step

Environment info

  • OS: Ubuntu 17.04
  • Python version: 2.7
  • Sphinx version: 1.6.1

Analysis

You really need to either change SuppressWarning to not fail if app.config is not present (but you may have other problems) or delay installing the SuppressWarning filter until after the Sphinx object was fully initialized.

bug config

Most helpful comment

Waw that was quick ! Thank you a lot for your reactivity. You folks are the best 🍰 ✨

All 3 comments

If you need a hand for a PR, let me know. Thing is, I'm blocked from upgrading because of this.

Thank you for reporting.
Fixed at ec50d01.

Waw that was quick ! Thank you a lot for your reactivity. You folks are the best 🍰 ✨

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shimizukawa picture shimizukawa  ·  3Comments

Paebbels picture Paebbels  ·  3Comments

shimizukawa picture shimizukawa  ·  3Comments

pgjones picture pgjones  ·  3Comments

ubershmekel picture ubershmekel  ·  3Comments