2

Closed

pickling exceptions is incomplete; attributes get lost

description

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 2.7.0.40. Running the attached file in IronPython 2.7 results in the following:
 
[E:\projects]\IronPython27\ipy.exe picklebug.py
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 "picklebug.py", line 16, in <module>
File "picklebug.py", 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 at 8:36 PM by jdhardy
Migrated to GitHub.

comments

irmen wrote Nov 17, 2012 at 8:00 PM

Bug still occurs in ipy 2.7.3