Skip to content

Pickling is losing some fields on exceptions #103333

Closed
@csm10495

Description

@csm10495

Bug report

Say we have an AttributeError with some fields on it (like name). When we pickle and unpickle it, we can see that .name (at least) is lost (and set to None). Optimally those fields should still be in-tact on the unpickled instance.

C:\Users\csm10495\Desktop>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> a = AttributeError("test text", name="test name", obj="test obj")
>>> a.name
'test name'
>>> pickle.loads(pickle.dumps(a)).name
>>> pickle.loads(pickle.dumps(a))
AttributeError('test text')

Your environment

C:\Users\csm10495\Desktop>python --version
Python 3.11.0

C:\Users\csm10495\Desktop>ver

Microsoft Windows [Version 10.0.19045.2364]

C:\Users\csm10495\Desktop>

Same thing seems to happen on 3.10.7 and 3.11.3 as well.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions