This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients alexandre.vassalotti, serhiy.storchaka
Date 2017-04-06.05:59:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491458375.12.0.99955546052.issue30005@psf.upfronthosting.co.za>
In-reply-to
Content
Pickling and copying exceptions preserves only __dict__ attributes.

This includes writeable internal fields initialized in constructor:

>>> import pickle, copy
>>> e = StopIteration(12)
>>> e.value = 34
>>> e.value
34
>>> e2 = pickle.loads(pickle.dumps(e, 4))
>>> e2.value
12
>>> e2 = copy.copy(e)
>>> e2.value
12

And __slots__:

>>> class E(Exception): __slots__ = ('x', 'y')
... 
>>> e = E()
>>> e.x = 12
>>> e.x
12
>>> e2 = pickle.loads(pickle.dumps(e, 4))
>>> e2.x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: x
>>> e2 = copy.copy(e)
>>> e2.x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: x

__context__, __cause__ and __traceback__ are lost too (see issue29466).

Issue26579 is similar, but resolving it will not resolve this issue since BaseException has its own __reduce__ and __setstate__ implementations.

The solution of this issue will look similar to issue29998, but more complex and general.
History
Date User Action Args
2017-04-06 05:59:35serhiy.storchakasetrecipients: + serhiy.storchaka, alexandre.vassalotti
2017-04-06 05:59:35serhiy.storchakasetmessageid: <1491458375.12.0.99955546052.issue30005@psf.upfronthosting.co.za>
2017-04-06 05:59:35serhiy.storchakalinkissue30005 messages
2017-04-06 05:59:34serhiy.storchakacreate