You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pickle does not serialize Exception __cause__ field #73652
Some stuff may be lost in time here, though for my benefit: Why don't the fields on exceptions go into __dict__? If they were there wouldn't serialization work closer-to 'for free'?
Activity
diekhans commentedon Feb 6, 2017
python3 pickle does not serialize the __cause__ field, as shown by the attached demo program.
serhiy-storchaka commentedon Feb 8, 2017
True. Attributes __context__, __cause__ and __traceback__ are not pickled. The traceback objects are even not pickleable.
What is worse, some other non-special attributes are lost during pickling. For example name and path attributes of ImportError.
Or the value attribute of StopIteration if it was not passed to the constructor.
kakshay21 commentedon Feb 16, 2019
Hey, can I work on this?
iritkatriel commentedon Jun 27, 2021
I get different output for Serhiy's first example now, but the same for the second:
iritkatriel commentedon Jun 27, 2021
See also bpo-43460, bpo-32696, bpo-30005.
iritkatriel commentedon Jan 6, 2022
It's not guaranteed that the __cause__ and __context__ are picklable either.
Should we try to pickle them, or should we document this and suggest traceback.TracebackException for storing or transmitting exception information?
csm10495 commentedon Apr 7, 2023
Some stuff may be lost in time here, though for my benefit: Why don't the fields on exceptions go into
__dict__? If they were there wouldn't serialization work closer-to 'for free'?