← 输入框|github.com|刷新
Skip to content

Cannot unpickle classes derived from 'Exception' #61498

Closed

Description

@AndreasHausmann
BPO 17296
Nosy @loewis, @brettcannon, @birkenfeld, @facundobatista, @jaraco, @abalkin, @pitrou, @vstinner, @avassalotti, @benjaminp, @bitdancer, @ambv
Files
  • bug_cpickle.py
  • bug_cpickle.py
  • exception_pickling.patch
  • issue_17296.patch
  • issue_17296v2.patch: Version 2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-03-06.20:04:29.705>
    created_at = <Date 2013-02-25.17:00:16.411>
    labels = ['interpreter-core', 'type-bug']
    title = "Cannot unpickle classes derived from 'Exception'"
    updated_at = <Date 2020-03-06.20:04:29.704>
    user = 'https://bugs.python.org/AndreasHausmann'

    bugs.python.org fields:

    activity = <Date 2020-03-06.20:04:29.704>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-06.20:04:29.705>
    closer = 'brett.cannon'
    components = ['Interpreter Core']
    creation = <Date 2013-02-25.17:00:16.411>
    creator = 'Andreas.Hausmann'
    dependencies = []
    files = ['29234', '29235', '29262', '29373', '29381']
    hgrepos = []
    issue_num = 17296
    keywords = ['patch']
    message_count = 13.0
    messages = ['182960', '182961', '182962', '182963', '182964', '183037', '183038', '183151', '183152', '183944', '183955', '183982', '363539']
    nosy_count = 26.0
    nosy_names = ['loewis', 'nnorwitz', 'brett.cannon', 'georg.brandl', 'facundobatista', 'jafo', 'ehuss', 'tseaver', 'jaraco', 'belopolsky', 'zseil', 'fmitha', 'pitrou', 'vstinner', 'alexandre.vassalotti', 'benjamin.peterson', 'jarpa', 'bpb', 'r.david.murray', 'zbysz', 'kylev', 'lukasz.langa', 'python-dev', 'sbt', 'Andreas.Hausmann', 'Aman.Shah']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17296'
    versions = ['Python 2.7', 'Python 3.2']

    Activity

    1. AndreasHausmann commented on Feb 25, 2013

      AndreasHausmannmannequin
      MannequinAuthor

      When pickling/unpickling a class that derives from the builtin class Exception, unpickling results in a

      TypeError: ('__init__() takes at least 2 arguments (1 given)', <class '__main__.TestException'>, ())

      A standard exception like ValueError can be pickled/unpickled without any problem.

      This was observed for versions 2.7.3 and 3.2.3. for both pickle and cPickle.

      A script (cpickle) that shows that behavior is included.

      This is related (but I do not quite understand how) to the closed bpo-1692335.

    2. added
      interpreter-core
      type-bug
      on Feb 25, 2013
    3. bitdancer commented on Feb 25, 2013

      @bitdancer
      Member

      That issue was only fixed in 3.3. Does your code work in 3.3?

    4. AndreasHausmann commented on Feb 25, 2013

      AndreasHausmannmannequin
      MannequinAuthor

      I have not tried in 3.3. I have no running installation of 3.3.

      I need a solution for 2.7 for a Zope project that was just ported to 2.7. My test for Python3 was halfheartedly on my standard Python3 installation (3.2) after reading bpo-1692335.

    5. bitdancer commented on Feb 25, 2013

      @bitdancer
      Member

      The reason I ask is because that issue ends with "reopen if you think this should be backported", so a backport is at least within the real of possibility :)

    6. bitdancer commented on Feb 25, 2013

      @bitdancer
      Member

      I modified your script to run under both python2 and python3. I get the error for 2.5, 2.6, and 2.7. The script produces the same output (without the EXCEPTION ## EXCEPTION) under 2.4 and 3.3.

    7. AndreasHausmann commented on Feb 26, 2013

      AndreasHausmannmannequin
      MannequinAuthor

      That is correct.

      Under 2.4 and 3.3 it should show neither the line "EXCEPTION ## EXCEPTION" nor the following line "TypeError: ('__init__() takes at least 2 arguments....."

      That means, that in version 2.4 and 3.3 that unpickling problem doesn't exist. In version 2.4 I tested it myself; exactly, there is no problem. In version 3.3 I simply take your word, that the bug is fixed.

    8. AndreasHausmann commented on Feb 26, 2013

      AndreasHausmannmannequin
      MannequinAuthor

      A backport to 2.7 would be in the interest of the Zope community (I dare say ;)), at least in ours.

      In our project, after having migrated to Zope 2.13/Python2.7 we found this bug and now we are quite worried what else might happen with our huge pickled database.

    9. bitdancer commented on Feb 27, 2013

      @bitdancer
      Member

      I don't have the expertise required to do the 2.7 backport. My naive attempt is attached, but the message attribute is not preserved (test failure). If someone can fix the patch, I'll commit it.

    10. python-dev commented on Feb 27, 2013

      python-devmannequin
      Mannequin

      New changeset 2c9f7ed28384 by R David Murray in branch '3.2':
      bpo-17296: backport fix for bpo-1692335, naive exception pickling.
      http://hg.python.org/cpython/rev/2c9f7ed28384

    11. AmanShah commented on Mar 11, 2013

      AmanShahmannequin
      Mannequin

      Fixed the patch for 2.7

    12. tseaver commented on Mar 11, 2013

      @tseaver

      The latest 2.7 patch does not cause the following tests (from
      bpo-1692335) to pass:

      http://bugs.python.org/file17509/issue1692335-tests.patch

    13. AmanShah commented on Mar 11, 2013

      AmanShahmannequin
      Mannequin

      I think it works with the other test also now. Have also included the failed test mentioned by Tres in the patch since it wasn't present in the python2.7 test suite.

    14. brettcannon commented on Mar 6, 2020

      @brettcannon
      Member

      As this was fixed in 3.3 that means all actively maintained versions have the fix, and so closing as fixed.

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      interpreter-coretype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions