This project has moved. For the latest updates, please go here.


pickling exceptions is incomplete; attributes get lost


Pickling an Exception object is not working properly. Any attributes that are present on the object get lost. Doing the same on a regular object works fine. Tested with IronPython Running the attached file in IronPython 2.7 results in the following:
test with MyClass...
reduce= (<built-in function _reconstructor>, (<class 'main.MyClass'>, <type 'object'>, None), {'
some_attribute': 42})
some_attribute= 42
test with Exception...
reduce= (<type 'exceptions.Exception'>, ('some exception',))
some_attribute=Traceback (most recent call last):
File "", line 16, in <module>
File "", line 11, in test
AttributeError: 'Exception' object has no attribute 'some_attribute'
As you can see, the __reduce__() on the Exception object doesn't include the extra attributes (it does on the normal object). After unpickling, the 'some_attribute' attribute that was set, is lost. Running the file in CPython 2.7 works fine.
Perhaps related to bug item #25731

file attachments

Closed Dec 9, 2014 at 7:36 PM by jdhardy
Migrated to GitHub.


irmen wrote Nov 17, 2012 at 7:00 PM

Bug still occurs in ipy 2.7.3

wrote Feb 22, 2013 at 1:09 AM

wrote Dec 9, 2014 at 7:36 PM