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: Unpickling exceptions pickled by Python 2
Type: behavior Stage: resolved
Components: Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: Arfrever, alexandre.vassalotti, doerwalter, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2013-11-29 15:49 by doerwalter, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-2-exception-pickling.diff doerwalter, 2013-11-30 15:51 review
python-2-exception-pickling-2.diff doerwalter, 2013-12-01 09:33 review
Messages (8)
msg204733 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2013-11-29 15:49
Exception objects that have been pickled with Python 2 can not be unpickled with Python 3, even when fix_imports=True is specified:

  $ python2.7
  Python 2.7.2 (default, Aug 30 2011, 11:04:13)
  [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import pickle
  >>> pickle.dumps(StopIteration())
  'cexceptions\nStopIteration\np0\n(tRp1\n.'
  >>>
  $ python3.3
  Python 3.3.2 (default, Nov 14 2013, 12:22:14)
  [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import pickle
  >>> pickle.loads(b'cexceptions\nStopIteration\np0\n(tRp1\n.', fix_imports=True)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  ImportError: No module named 'exceptions'
  >>>

Adding an entry "exceptions": "builtins" to _compat_pickle.IMPORT_MAPPING seems to fix the problem.
msg204762 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-30 00:34
Good catch! Would you like to provide a patch together with an added unit test?
msg204823 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2013-11-30 15:51
OK, here is a patch. Instead of mapping the exceptions module to builtins, it does the mapping for each exception class separately. I've excluded StandardError, because I think there's no appropriate equivalent in Python 3.
msg204841 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-11-30 19:46
I have reviewed the patch in the review tool. Please take a look!
msg204894 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2013-12-01 09:33
Here's an updated version of the patch, addressing most of Alexandre's comments.
msg204986 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2013-12-02 01:10
Feel free to commit once you have addressed the remaining comments.
msg204996 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-02 10:44
New changeset 7d3297f127ae by Walter Doerwald in branch '3.3':
Fix issue #19834: Support unpickling of exceptions pickled by Python 2.
http://hg.python.org/cpython/rev/7d3297f127ae

New changeset 9685c9d1d67f by Walter Doerwald in branch 'default':
Fix #19834: merge with 3.3.
http://hg.python.org/cpython/rev/9685c9d1d67f
msg205024 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-02 16:21
New changeset a270370ec487 by Walter Doerwald in branch '3.3':
Add NEWS entry for issue #19834.
http://hg.python.org/cpython/rev/a270370ec487

New changeset ef6ad7172d50 by Walter Doerwald in branch 'default':
Add NEWS entry for issue #19834: merge with 3.3.
http://hg.python.org/cpython/rev/ef6ad7172d50
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64033
2014-12-05 04:26:39Arfreversetstage: needs patch -> resolved
2014-12-04 20:05:19doerwaltersetstatus: open -> closed
2013-12-02 16:21:29python-devsetmessages: + msg205024
2013-12-02 10:46:06doerwaltersetresolution: fixed
2013-12-02 10:44:22python-devsetnosy: + python-dev
messages: + msg204996
2013-12-02 01:10:44alexandre.vassalottisetassignee: doerwalter
messages: + msg204986
2013-12-01 09:33:02doerwaltersetfiles: + python-2-exception-pickling-2.diff

messages: + msg204894
2013-11-30 19:46:58alexandre.vassalottisetmessages: + msg204841
2013-11-30 15:51:43doerwaltersetfiles: + python-2-exception-pickling.diff
keywords: + patch
messages: + msg204823
2013-11-30 00:34:54pitrousetmessages: + msg204762
stage: needs patch
2013-11-29 20:53:47Arfreversetnosy: + Arfrever
2013-11-29 16:57:11serhiy.storchakasetnosy: + pitrou, alexandre.vassalotti

type: behavior
versions: + Python 3.3, Python 3.4
2013-11-29 15:49:14doerwaltercreate