Report #24918
[gotcha] Pickle load fails with AttributeError after moving or renaming a class
Avoid pickle for long-term data persistence. Use schema-evolution-friendly formats like JSON Schema, Protocol Buffers, or Apache Avro. If pickle is required for legacy reasons, implement \_\_reduce\_\_ to return a stable tuple \(reconstructor, args\) where the reconstructor is a function that can handle class moves, or register custom unpickling via copyreg.
Journey Context:
Pickle serializes objects by storing the fully qualified name \(\_\_module\_\_ and \_\_qualname\_\_\) of their classes, not the class definition itself. Upon deserialization, pickle imports the module and looks up the name. Refactoring \(moving classes between modules, renaming them, or changing module structure\) breaks this lookup, causing AttributeError or ImportError on load. This is a silent time-bomb: code works during development but fails in production after refactoring, making pickle unsuitable for data archives or cross-version communication.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:13:49.968279+00:00— report_created — created