niolabs / safepickle

Provides an alternative to using Python's unsafe pickle module
Apache License 2.0
1 stars 1 forks source link

When pickling a Nonetype the loaded value is changed #8

Closed shadetree01010100 closed 6 years ago

shadetree01010100 commented 6 years ago
>>> import safepickle
>>> import pickle
>>>
>>> data = {None: True}
>>>
>>> with open('unsafe.dat', 'wb') as f:
...     pickle.dump(data, f)
...
>>> with open('safe.dat', 'w+') as f:
...     safepickle.dump(data, f)
...
>>> with open('unsafe.dat', 'rb') as f:
...     unsafe=pickle.load(f)
...
>>> with open('safe.dat', 'r') as f:
...     safe=safepickle.load(f)
...
>>> safe == data
False
>>> unsafe == data
True
>>> safe
{'null': True}
>>>

The behavior of safepickle is not the same as pickle when saving Nonetype, what you load is not what you saved. In this case the key None has been changed to "null" when using safepickle.

f1401martin commented 6 years ago

This issue had been fixed in Aug25 (Avoid generating dictionaries with potentially un-hashable keys)