Skip to content

assertion failure at Objects/call.c:618: PyObject *callmethod(PyThreadState *, PyObject *, const char *, struct __va_list_tag *): Assertion 'callable != NULL' failed. #142737

Closed

Description

@YuanchengJiang

Crash report

What happened?

import builtins
import sys

def test_import(name, *args, **kwargs):
    sys.modules[name] = object()
    return sys.modules[name]

builtins.__import__ = test_import

raise RuntimeError("Test")
python: ../Objects/call.c:618: PyObject *callmethod(PyThreadState *, PyObject *, const char *, struct __va_list_tag *): Assertion `callable != NULL' failed.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Linked PRs

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Dec 15, 2025
  2. johnslavik commented on Dec 15, 2025

    @johnslavik
    Member

    Full message (please include it when possible):

    Exception ignored in the internal traceback machinery:
    AttributeError: 'object' object has no attribute '_print_exception_bltin'
    Traceback (most recent call last):
      File "/home/bswck/Python/cpython/t.py", line 12, in <module>
    python: Objects/call.c:618: callmethod: Assertion `callable != NULL' failed.
    Fatal Python error: Aborted
    Aborted (core dumped)
    

    The problem happens because _Py_FindSourceFile resorts to _PyObject_CallMethodFormat which assumes callable is healthy (the callable in this case is the result of getting open of io, which is NULL because io is an object() from test_import).
    Maybe NULL-check the callable first? (PR in progress)

  3. ZeroIntensity commented on Dec 15, 2025

    @ZeroIntensity
    Member

    Maybe NULL-check the callable first? (PR in progress)

    I think the issue is here:

    cpython/Python/traceback.c

    Lines 417 to 420 in 14d3974

    open = PyObject_GetAttr(io, &_Py_ID(open));
    for (i = 0; i < npath; i++) {
    v = PyList_GetItem(syspath, i);
    if (v == NULL) {

    We need to check for a NULL result from PyObject_GetAttr, not defer the check to _PyObject_CallMethodFormat, because:

    1. That will slow things down for other callers.
    2. It's generally unsafe to call arbitrary C API functions with an exception set.
  4. johnslavik commented on Dec 15, 2025

    @johnslavik
    Member

    Would slow down for other callers of _Py_FindSourceFile -- there are no other callers of _PyObject_CallMethodFormat than traceback.c itself.

    I think we can skip the entire loop actually, if open is NULL?

  5. ZeroIntensity commented on Dec 15, 2025

    @ZeroIntensity
    Member

    Would slow down for other callers of _Py_FindSourceFile -- there are no other callers of _PyObject_CallMethodFormat than traceback.c itself.

    Then I assume that API was added with the intention that we'll use it somewhere else someday.

    I think we can skip the entire loop actually, if open is NULL?

    Yeah, that makes sense to me.

  6. added a commit that references this issue on Dec 15, 2025
  7. added a commit that references this issue on Dec 15, 2025
  8. added 2 commits that reference this issue on Dec 15, 2025
  9. added 2 commits that reference this issue on Dec 15, 2025
  10. added a commit that references this issue on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions