Issue 29466: pickle does not serialize Exception __cause__ field
Created on 2017-02-06 18:36 by diekhans, last changed 2022-04-11 14:58 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| cause_pickle.py | diekhans, 2017-02-06 18:36 | bug demog program | ||
| Messages (6) | |||
|---|---|---|---|
| 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) * ![]() |
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? |
|||
| msg396603 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2021-06-27 21:41 | |
I get different output for Serhiy's first example now, but the same for the second:
>>> try: import foo
... except Exception as ex: exc = ex
...
>>> exc.name
'foo'
>>> exc.__reduce__()
(<class 'ModuleNotFoundError'>, ("No module named 'foo'",), {'name': 'foo'})
>>> exc = StopIteration()
>>> exc.value = 42
>>> exc.__reduce__()
(<class 'StopIteration'>, ())
>>>
|
|||
| msg396604 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2021-06-27 21:41 | |
See also issue43460, issue32696, issue30005. |
|||
| msg409871 - (view) | Author: Irit Katriel (iritkatriel) * ![]() |
Date: 2022-01-06 16:21 | |
> Attributes __context__, __cause__ and __traceback__ are not pickled. The traceback objects are even not pickleable. 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? |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:42 | admin | set | github: 73652 |
| 2022-01-06 16:21:58 | iritkatriel | set | messages: + msg409871 |
| 2021-06-27 21:41:37 | iritkatriel | set | messages: + msg396604 |
| 2021-06-27 21:41:18 | iritkatriel | set | nosy:
+ iritkatriel messages:
+ msg396603 |
| 2019-02-16 14:15:36 | kakshay | set | nosy:
+ kakshay messages: + msg335686 |
| 2019-02-14 05:29:16 | tjb900 | set | nosy:
+ tjb900 |
| 2017-02-08 11:55:09 | serhiy.storchaka | set | nosy:
+ brett.cannon, ncoghlan, eric.snow messages: + msg287304 |
| 2017-02-07 02:47:24 | xiang.zhang | set | nosy:
+ serhiy.storchaka |
| 2017-02-06 19:22:50 | diekhans | set | nosy:
+ alexandre.vassalotti |
| 2017-02-06 18:36:36 | diekhans | create | |
