[issue37287] picke cannot dump exceptions subclasses with different super() args

Brian Quinlan report at bugs.python.org
Fri Jun 14 19:30:45 EDT 2019


New submission from Brian Quinlan <brian at sweetapp.com>:

$ ./python.exe nopickle.py
TypeError: __init__() missing 1 required positional argument: 'num'

The issue is that the arguments passed to Exception.__init__ (via `super()`) are collected into `args` and then serialized by pickle e.g.

>>> PickleBreaker(5).args
()
>>> PickleBreaker(5).__reduce_ex__(3)
(<class '__main__.PoolBreaker'>, (), {'num': 5})
>>> # The 1st index is the `args` tuple

Then, during load, the `args` tuple is used to initialize the Exception i.e. PickleBreaker(), which results in the `TypeError`

See https://github.com/python/cpython/blob/master/Modules/_pickle.c#L6769

----------
components: Library (Lib)
files: nopickle.py
messages: 345647
nosy: bquinlan
priority: normal
severity: normal
status: open
title: picke cannot dump exceptions subclasses with different super() args
versions: Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48420/nopickle.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37287>
_______________________________________


More information about the Python-bugs-list mailing list