classification
Title: pickle does not serialize Exception __cause__ field
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, brett.cannon, diekhans, eric.snow, kakshay, ncoghlan, serhiy.storchaka, tjb900
Priority: normal Keywords:

Created on 2017-02-06 18:36 by diekhans, last changed 2019-02-16 14:15 by kakshay.

Files
File name Uploaded Description Edit
cause_pickle.py diekhans, 2017-02-06 18:36 bug demog program
Messages (3)
msg287163 - (view) Author: Mark Diekhans (diekhans) Date: 2017-02-06 18:36
python3 pickle does not serialize the __cause__ field, as shown by the attached demo program.
msg287304 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-02-08 11:55
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.

>>> try: import foo
... except Exception as ex: exc = ex
... 
>>> exc.name
'foo'
>>> exc.__reduce__()
(<class 'ModuleNotFoundError'>, ("No module named 'foo'",), {})

Or the value attribute of StopIteration if it was not passed to the constructor.

>>> exc = StopIteration()
>>> exc.value = 42
>>> exc.__reduce__()
(<class 'StopIteration'>, (), {})
msg335686 - (view) Author: Kumar Akshay (kakshay) * Date: 2019-02-16 14:15
Hey, can I work on this?
History
Date User Action Args
2019-02-16 14:15:36kakshaysetnosy: + kakshay
messages: + msg335686
2019-02-14 05:29:16tjb900setnosy: + tjb900
2017-02-08 11:55:09serhiy.storchakasetnosy: + brett.cannon, ncoghlan, eric.snow
messages: + msg287304
2017-02-07 02:47:24xiang.zhangsetnosy: + serhiy.storchaka
2017-02-06 19:22:50diekhanssetnosy: + alexandre.vassalotti
2017-02-06 18:36:36diekhanscreate