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: pickle exceptions with mandatory keyword args will traceback
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: a.badger, remi.lapeyre
Priority: normal Keywords:

Created on 2020-06-08 23:46 by a.badger, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg371057 - (view) Author: Toshio Kuratomi (a.badger) * Date: 2020-06-08 23:46
I was trying to use multiprocessing (via a concurrent.futures.ProcessPoolExecutor) and encountered an error when pickling a custom Exception.  On closer examination I was able to create a simple test case that only involves pickle:


import pickle
class StrRegexError(Exception):
    def __init__(self, *, pattern):
        self.pattern = pattern

data = pickle.dumps(StrRegexError(pattern='test'))
instance = pickle.loads(data)


[pts/11@peru /srv/ansible]$ python3.8 ~/p.py
Traceback (most recent call last):
  File "/home/badger/p.py", line 7, in <module>
    instance = pickle.loads(data)
TypeError: __init__() missing 1 required keyword-only argument: 'pattern'

pickle can handle mandatory keyword args in other classes derived from object; it's only classes derived from Exception that have issues.
msg371075 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-06-09 06:16
This is a duplicate of issue 27015.
msg371328 - (view) Author: Toshio Kuratomi (a.badger) * Date: 2020-06-12 02:00
Thanks!  I confirm that your PR  https://github.com/python/cpython/pull/11580 for https://bugs.python.org/issue27015 fixes this problem.

Closing this one.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85094
2020-06-12 02:00:02a.badgersetstatus: open -> closed
resolution: duplicate
messages: + msg371328

stage: resolved
2020-06-09 06:16:36remi.lapeyresetnosy: + remi.lapeyre

messages: + msg371075
versions: + Python 3.9, Python 3.10, - Python 3.6
2020-06-09 00:53:50a.badgersettitle: pickling exceptions with mandatory keyword args will traceback -> pickle exceptions with mandatory keyword args will traceback
2020-06-08 23:46:10a.badgercreate