-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Closed as not planned
Closed as not planned
Copy link
Labels
3.10only security fixesonly security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
pickle protocol 1 silently fails / causes data loss with __slots__ = ()
copyreg._reduce_ex falls back on falsy __slots__ to __dict__ which is then not available.
State becomes None, leading to data loss.
class Slotted():
__slots__ = 'mapping',
def __init__(self, mapping):
self.mapping = mapping
class NotSlotted(Slotted):
__slots__ = ()
m = NotSlotted({'abc':'cde'})
state = pickle.dumps(m, protocol=2)
loaded = pickle.loads(state)
assert loaded.mapping == m.mapping
state = pickle.dumps(m, protocol=1)
loaded = pickle.loads(state)
assert loaded.mapping == m.mapping
fails with
File "fail.py", line 23, in <module>
assert loaded.mapping == m.mapping
AttributeError: mapping
Discovered this with collections.abc.MappingView and subclasses
Your environment
- CPython versions tested on: 3.9.5
- Operating system and architecture: ubuntu x86_64
Metadata
Metadata
Assignees
Labels
3.10only security fixesonly security fixestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done

