It sounds like the class definition of whatever dataclass you are using has changed to include a hash. Unfortunately, you can't pickle a hash, as a _hashlib.HASH object is a C object that doesn't provide pickling instructions (i.e. it can't be serialized). Here's an example, using dill
with different serialization settings (to mimic pickle
and cloudpickle
):
>>> import hashlib
>>> hash = hashlib.md5()
>>> import dill
>>> dill.dumps(hash) # default: global by-value
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 263, in dumps
dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 235, in dump
Pickler(file, protocol, **_kwds).dump(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 394, in dump
StockPickler.dump(self, obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 437, in dump
self.save(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 388, in save
StockPickler.save(self, obj, save_persistent_id)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 524, in save
rv = reduce(self.proto)
TypeError: can't pickle _hashlib.HASH objects
>>>
>>> # change to "cloudpickle" settings (pointer-trace by-value)
>>> dill.settings['recurse'] = True
>>> dill.dumps(hash)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 263, in dumps
dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 235, in dump
Pickler(file, protocol, **_kwds).dump(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 394, in dump
StockPickler.dump(self, obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 437, in dump
self.save(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 388, in save
StockPickler.save(self, obj, save_persistent_id)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 524, in save
rv = reduce(self.proto)
TypeError: can't pickle _hashlib.HASH objects
>>>
>>> # change to "pickle" settings (by reference)
>>> dill.settings['byref'] = True
>>> dill.dumps(hash)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 263, in dumps
dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 235, in dump
Pickler(file, protocol, **_kwds).dump(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 394, in dump
StockPickler.dump(self, obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 437, in dump
self.save(obj)
File "/Users/mmckerns/lib/python3.7/site-packages/dill/_dill.py", line 388, in save
StockPickler.save(self, obj, save_persistent_id)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pickle.py", line 524, in save
rv = reduce(self.proto)
TypeError: can't pickle _hashlib.HASH objects
Depending on where a hash is used in the dataclass object, one of the above variants may succeed.