-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pickle does not serialize Exception __cause__ field #73652
Comments
python3 pickle does not serialize the __cause__ field, as shown by the attached demo program. |
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'>, (), {}) |
Hey, can I work on this? |
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'>, ())
>>> |
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? |
Some stuff may be lost in time here, though for my benefit: Why don't the fields on exceptions go into |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: