This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: pydoc search chokes on import errors
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: martin.panter, pitrou, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-05-18 17:05 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
pydoc_search_onerror.patch pitrou, 2013-05-18 20:03 review
pydoc_search_onerror.v2.patch martin.panter, 2015-11-02 03:36 review
gui-search.patch martin.panter, 2015-11-06 02:01 For 2.7 review
Messages (12)
msg189536 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-18 17:05
After installing Django, I get the following error in test_pydoc:

FAIL: test_url_requests (test.test_pydoc.PydocUrlHandlerTest)
Traceback (most recent call last):
  File "/home/antoine/cpython/finalize/Lib/test/", line 581, in test_url_requests
    self.assertEqual(result, title, text)
AssertionError: 'Pydoc: Error - search?key=pydoc' != 'Pydoc: Search Results'
- Pydoc: Error - search?key=pydoc
+ Pydoc: Search Results

The reason is attempting to import a django.something module raises the following error:

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

... which isn't silenced by pydoc.

Now I agree this is fundamentally obnoxious on Django's part, but unfortunately it isn't the only package (IIRC) to behave in this way, meaning it would be nice from pydoc to silence all such errors when an import is attempted.
msg189541 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-05-18 18:53
Isn't issue10060 related?
msg189543 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-18 19:47
Not exactly. issue10060 is about a crash when loading an extension module, not an exception being raised and propagated through pydoc.
msg189545 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-18 20:03
Patch attached.
msg253411 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-10-24 16:47
The patch looks good.
msg253412 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-10-24 17:09
Would be nice to have a test.
msg253892 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-02 03:36
Here is a test case. I had to insert a temporary directory into sys.path, based off my patch in Issue 25184. Let me know if it doesn’t look too evil :)
msg254139 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-05 20:24
Oh, I were not expected that the test will be so complex, and now I'm not sure that want it. :-(  But looks it can't be written simpler. The patch LGTM in any case.
msg254156 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-06 01:10
New changeset 9098731de840 by Martin Panter in branch '3.4':
Issue #18010: Fix pydoc web server search to handle package exceptions

New changeset 8702efa1feb4 by Martin Panter in branch '3.5':
Issue #18010: Merge pydoc web search fix from 3.4 into 3.5

New changeset d86ff708f545 by Martin Panter in branch 'default':
Issue #18010: Merge pydoc web search fix from 3.5
msg254162 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-11-06 02:01
In Python 2, it looks like instead of the web server search function there is a GUI search function. Here is a patch to fix the equivalent problem there. However I am not volunteering to make a test case; there does not seem to be any GUI tests to start with.
msg254171 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-06 07:32
gui-search.patch LGTM.
msg254257 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-07 06:00
New changeset 1ab20d3c9dc6 by Martin Panter in branch '2.7':
Issue #18010: Fix pydoc GUI search to handle package exceptions
Date User Action Args
2022-04-11 14:57:45adminsetgithub: 62210
2015-11-07 06:06:43martin.pantersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-11-07 06:01:00python-devsetmessages: + msg254257
2015-11-06 07:32:02serhiy.storchakasetmessages: + msg254171
2015-11-06 02:01:18martin.pantersetfiles: + gui-search.patch

messages: + msg254162
stage: commit review -> patch review
2015-11-06 01:10:00python-devsetnosy: + python-dev
messages: + msg254156
2015-11-05 20:24:32serhiy.storchakasetstage: patch review -> commit review
2015-11-05 20:24:23serhiy.storchakasetmessages: + msg254139
2015-11-02 03:36:18martin.pantersetfiles: + pydoc_search_onerror.v2.patch

nosy: + martin.panter
messages: + msg253892

stage: test needed -> patch review
2015-10-24 17:09:30serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg253412
2015-10-24 16:47:29rhettingersetnosy: + rhettinger
messages: + msg253411
2015-10-24 14:56:35serhiy.storchakasetstage: needs patch -> test needed
versions: + Python 3.5, Python 3.6, - Python 3.3
2013-12-09 19:24:33serhiy.storchakasetnosy: - serhiy.storchaka
2013-05-18 20:03:03pitrousetfiles: + pydoc_search_onerror.patch
keywords: + patch
messages: + msg189545
2013-05-18 19:47:42pitrousetmessages: + msg189543
2013-05-18 18:53:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg189541
2013-05-18 17:05:19pitroucreate