Skip to content

Failure.__getstate__ is ignored by pickle #12112

@itamarst

Description

@itamarst
  1. Failure subsclasses BaseException.
  2. BaseException implements the reduce pickle API, in C.
  3. As a result, you need to override __reduce__ to impact pickling behavior.

Demonstration—notice that Failure.__getstate__ does c["pickled"] = 1 in its implementation in the dictionary it returns.

Python 3.11.8 (main, Feb 25 2024, 16:39:33) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from twisted.python.failure import Failure
>>> f = Failure(ZeroDivisionError())
>>> pickle.loads(pickle.dumps(f)).pickled
0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions