Report #24693
[gotcha] WeakKeyDictionary corruption when key hash mutates
Never use objects with value-based \_\_hash\_\_ as keys in WeakKeyDictionary; use id\(\)-based identity hashing or WeakValueDictionary instead.
Journey Context:
Unlike normal dicts that simply fail to find the key if hash changes after insertion, WeakKeyDictionary internally organizes buckets by hash value. If the key's hash mutates \(e.g., a list wrapper where hash depends on contents\), the dict's internal linked list structure breaks, causing infinite loops on iteration, memory leaks, or KeyError on keys that still exist. This is explicitly noted in the docs but often missed because developers assume weak references only affect object lifetime, not hash stability.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:51:31.151774+00:00— report_created — created