Skip to content

Failing to load a module in _PyImport_GetModuleExportHooks can result in a !_PyErr_Occurred(tstate) error #141169

@DinoV

Description

@DinoV

Bug report

Bug description:

Ran into this on 3.15 main... I don't have libuuid available on my Linux machine, and import _uuid results in: "python3.15: third-party/python/main/patched/Objects/call.c:120: PyObject *_PyObject_VectorcallDictTstate(PyThreadState *, PyObject *, PyObject *const *, size_t, PyObject *): Assertion `!_PyErr_Occurred(tstate)' failed."

The issue seems to be that _PyImport_GetModuleExportHooks does the findfuncptr for export_prefix which results in an ImportError being set. Then it does it again for init_prefix and that again tries setting an ImportError resulting in the failed assertion.

I'd be happy to put up a PR but I'm not sure if the correct behavior is:

  1. PyErr_Clear after the first failed attempt
  2. PyErr_Fetch after the first failed attempt, and PyErr_Restore if the 2nd one doesn't succeed
  3. PyErr_Fetch after the first failed attempt, and leave the error of the 2nd one if it reported an error, or PyErr_Restore if it doesn't.

The new code was added with 589a03a

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions