Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum.IntFlag (un)pickles incorrectly on Python 3.12 (and differently on Python 3.11) #105332

Closed
da-woods opened this issue Jun 5, 2023 · 5 comments
Assignees
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@da-woods
Copy link
Contributor

da-woods commented Jun 5, 2023

Bug report

Run the following code:

import enum
import pickle

class PxdEnum(enum.IntFlag):
    RANK_0 = 11
    RANK_1 = 37
    RANK_2 = 389

print(pickle.loads(pickle.dumps(PxdEnum.RANK_2)))

On Python 3.10.10 I get PxdEnum.RANK_2
On Python 3.11.2 I get 389 (which is probably also acceptable)
On Python 3.12 (0aaef83351473e8f4eb774f8f999bbe87a4866d7) I get

Traceback (most recent call last):
  File "<path>/enumpickle.py", line 9, in <module>
    print(pickle.loads(pickle.dumps(PxdEnum.RANK_2)))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for |: 'PxdEnum' and 'NoneType'

Your environment

Tested as described on Python 3.10, 3.11, and 3.12.
Linux

Linked PRs

@da-woods da-woods added the type-bug An unexpected behavior, bug, or error label Jun 5, 2023
@da-woods da-woods changed the title Change enum.Flag (un)pickles incorrectly on Python 3.12 (and differently on Python 3.11) enum.Flag (un)pickles incorrectly on Python 3.12 (and differently on Python 3.11) Jun 5, 2023
@da-woods da-woods changed the title enum.Flag (un)pickles incorrectly on Python 3.12 (and differently on Python 3.11) enum.IntFlag (un)pickles incorrectly on Python 3.12 (and differently on Python 3.11) Jun 5, 2023
@AlexWaygood AlexWaygood added stdlib Python modules in the Lib dir 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Jun 5, 2023
@sobolevn
Copy link
Member

sobolevn commented Jun 6, 2023

The same also happens with Flag as well:

import enum
import pickle

class PxdEnum(enum.Flag):
    RANK_0 = 11
    RANK_1 = 37
    RANK_2 = 389

d = pickle.dumps(PxdEnum.RANK_2)
print('--')
print(pickle.loads(d))

The offending commit is 5369858

I am working on a fix! Thanks for the report.

@sobolevn
Copy link
Member

sobolevn commented Jun 6, 2023

@da-woods in 3.11 only the representation was changed, it still gives Enum back:

Python 3.11.3 (main, May 27 2023, 12:23:35) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enum
>>> import pickle
>>> 
>>> class PxdEnum(enum.IntFlag):
...     RANK_0 = 11
...     RANK_1 = 37
...     RANK_2 = 389
... 
>>> print(pickle.loads(pickle.dumps(PxdEnum.RANK_2)))
389
>>> print(type(pickle.loads(pickle.dumps(PxdEnum.RANK_2))))
<flag 'PxdEnum'>

@da-woods
Copy link
Contributor Author

da-woods commented Jun 6, 2023

Thanks for the quick PR.

The change in representation wasn't a big worry - it didn't break anything for me. It was just something I spotted while preparing the checking the example and wasn't sure if it was relevant or not.

ethanfurman added a commit that referenced this issue Jun 8, 2023
* revert enum pickling from by-name to by-value

Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 8, 2023
…105348)

* revert enum pickling from by-name to by-value

(cherry picked from commit 4ff5690)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 8, 2023
…105348)

* revert enum pickling from by-name to by-value

(cherry picked from commit 4ff5690)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
ethanfurman added a commit that referenced this issue Jun 9, 2023
… (GH-105520)

* revert enum pickling from by-name to by-value

(cherry picked from commit 4ff5690)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
ethanfurman added a commit that referenced this issue Jun 9, 2023
… (GH-105519)

* revert enum pickling from by-name to by-value

(cherry picked from commit 4ff5690)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
@da-woods
Copy link
Contributor Author

da-woods commented Jun 9, 2023

This looks like it was fixed. Should I close the issue or is it waiting for anything?

@sobolevn
Copy link
Member

sobolevn commented Jun 9, 2023

Yes, it is fixed. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants