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.

classification
Title: Correctly unpickle exceptions
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, zseil
Priority: normal Keywords: patch

Created on 2006-05-31 23:21 by zseil, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
exceptions_setstate_update.diff zseil, 2006-06-01 01:44 patch against revision 46583
Messages (3)
msg50400 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2006-05-31 23:21
With recent changes to exception types, unpickling
exceptions that were pickled with an older version
of Python didn't restore all of the original
attributes. Example:

Python 2.4.3 (#69, Mar 29 2006, 17:35:34)
 ...
>>> import pickle
>>> f = open('jar', 'wb')
>>> e = Exception('cucumbers', 'cabbage')
>>> e.args
('cucumbers', 'cabbage')
>>> pickle.dump(e, f)
>>> f.close()
>>> f = open('jar', 'rb')
>>> e = pickle.load(f)
>>> f.close()
>>> e.args
('cucumbers', 'cabbage')

Python 2.5a2 (trunk:46539M, May 30 2006, 05:02:24)
  ...
>>> import pickle
>>> f = open('jar', 'rb')
>>> e = pickle.load(f)
>>> f.close()
>>> e.args
()
>>> e.__dict__['args']
('cucumbers', 'cabbage')

The attached patch fixes this problem, by adding
a __setstate__ method to BaseException. I don't
know if any new tests are needed, since pickling
exceptions is already tested and new tests would
require adding binary files to the test suite.
I did some basic tests that I can attach if
they are needed.
msg50401 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) Date: 2006-06-01 01:44
Logged In: YES 
user_id=1326842

Removed unnecessary cast.
msg50402 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-06-01 06:39
Logged In: YES 
user_id=849994

Applied as rev. 46585. Thanks!
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43442
2006-05-31 23:21:01zseilcreate