Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydoc search chokes on import errors #62210

Closed
pitrou opened this issue May 18, 2013 · 12 comments
Closed

pydoc search chokes on import errors #62210

pitrou opened this issue May 18, 2013 · 12 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented May 18, 2013

BPO 18010
Nosy @rhettinger, @pitrou, @vadmium, @serhiy-storchaka
Files
  • pydoc_search_onerror.patch
  • pydoc_search_onerror.v2.patch
  • gui-search.patch: For 2.7
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2015-11-07.06:06:43.426>
    created_at = <Date 2013-05-18.17:05:19.330>
    labels = ['type-bug', 'library']
    title = 'pydoc search chokes on import errors'
    updated_at = <Date 2015-11-07.06:06:43.426>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2015-11-07.06:06:43.426>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2015-11-07.06:06:43.426>
    closer = 'martin.panter'
    components = ['Library (Lib)']
    creation = <Date 2013-05-18.17:05:19.330>
    creator = 'pitrou'
    dependencies = []
    files = ['30306', '40924', '40959']
    hgrepos = []
    issue_num = 18010
    keywords = ['patch']
    message_count = 12.0
    messages = ['189536', '189541', '189543', '189545', '253411', '253412', '253892', '254139', '254156', '254162', '254171', '254257']
    nosy_count = 5.0
    nosy_names = ['rhettinger', 'pitrou', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18010'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @pitrou
    Copy link
    Member Author

    pitrou commented May 18, 2013

    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/test_pydoc.py", 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.

    @pitrou pitrou added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels May 18, 2013
    @serhiy-storchaka
    Copy link
    Member

    Isn't bpo-10060 related?

    @pitrou
    Copy link
    Member Author

    pitrou commented May 18, 2013

    Not exactly. bpo-10060 is about a crash when loading an extension module, not an exception being raised and propagated through pydoc.

    @pitrou
    Copy link
    Member Author

    pitrou commented May 18, 2013

    Patch attached.

    @rhettinger
    Copy link
    Contributor

    The patch looks good.

    @serhiy-storchaka
    Copy link
    Member

    Would be nice to have a test.

    @vadmium
    Copy link
    Member

    vadmium commented Nov 2, 2015

    Here is a test case. I had to insert a temporary directory into sys.path, based off my patch in bpo-25184. Let me know if it doesn’t look too evil :)

    @serhiy-storchaka
    Copy link
    Member

    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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 6, 2015

    New changeset 9098731de840 by Martin Panter in branch '3.4':
    Issue bpo-18010: Fix pydoc web server search to handle package exceptions
    https://hg.python.org/cpython/rev/9098731de840

    New changeset 8702efa1feb4 by Martin Panter in branch '3.5':
    Issue bpo-18010: Merge pydoc web search fix from 3.4 into 3.5
    https://hg.python.org/cpython/rev/8702efa1feb4

    New changeset d86ff708f545 by Martin Panter in branch 'default':
    Issue bpo-18010: Merge pydoc web search fix from 3.5
    https://hg.python.org/cpython/rev/d86ff708f545

    @vadmium
    Copy link
    Member

    vadmium commented Nov 6, 2015

    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.

    @serhiy-storchaka
    Copy link
    Member

    gui-search.patch LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 7, 2015

    New changeset 1ab20d3c9dc6 by Martin Panter in branch '2.7':
    Issue bpo-18010: Fix pydoc GUI search to handle package exceptions
    https://hg.python.org/cpython/rev/1ab20d3c9dc6

    @vadmium vadmium closed this as completed Nov 7, 2015
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants