_pickle.UnpicklingError: Memo value not found at index 1
未關閉
還沒有人認領這個 Issue。
3.12
3.13
3.14
docs
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
When pickling a container object. The pickler class will store child-objects to its self.memo even if the container could not be fully pickled (and not written to the output).
This can cause references to memo objects that are not in the output stream.
import sys
import pickle
import io
buf = io.BytesIO()
pickler = pickle.Pickler(buf)
i_will_be_memorized = 'qqqqqqqqqqqq'
i_cant_be_pickled = sys
try:
pickler.dump([i_will_be_memorized, i_cant_be_pickled])
except TypeError:
# i_will_be_memorized is now in pickler memory despite the exception
pass
# this dump will use the memo
pickler.dump(i_will_be_memorized)
data = buf.getbuffer().tobytes()
# so this will fail with:
# _pickle.UnpicklingError: Memo value not found at index 1
pickle.loads(data)
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-125762
- gh-130231
- gh-130232
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 issue 中的 Python pickle 和 io.BytesIO 程式碼片段重現該失敗,然後檢查 pickle.Pickler 在容器 dump 失敗時對 memo 的處理。完成的標準是,後續的 dump 不會參照輸出串流中不存在的 memo 項目,並且針對所示序列具備回歸測試涵蓋。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100