python / python/cpython

Crash because of ownership assert in `PyObject_ClearManagedDict`

Open
#152,254 0 comments 1 reaction 1 assignee View on GitHub

@sobolevn is already working on this.

Since Jun 26, 2026.

interpreter-core type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Crash report

Refs https://github.com/python/cpython/issues/151763
Original description: https://gist.github.com/devdanzin/99b84915b197ae0ade7face262b8af66

Repro:

from unittest.mock import MagicMock
from _testcapi import set_nomemory

set_nomemory(200)              # fail allocations from the 200th onward (lands in shutdown GC)
(MagicMock(), undefined_name)  # build a MagicMock (managed __dict__), then NameError abandons
                               # it into a traceback cycle -> survives to shutdown GC

I have a fix ready.

Linked PRs
  • gh-152255

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.