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

Python implementation of pickle calls persistent_id() for a persistent id #126489

Closed
serhiy-storchaka opened this issue Nov 6, 2024 · 0 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Nov 6, 2024

Bug report

Pickle allows to define the persistent_id() method in the Pickler class. If it is defined, it is called for every pickled object, and its result will be pickled instead if it is not None. In the Python implementation persistent_id() is also called for the result of persistent_id(), but the result of the second call is ignored. The C implementation only calls persistent_id() once. Calling it twice is just a waste of time in best case, and can have other negative impact (for example if reference for every object for which it was called is stored), so I consider it a bug.

It was found during work on #125752.

Linked PRs

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Nov 6, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 6, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Nov 6, 2024
…ython pickle (pythonGH-126490)

(cherry picked from commit 8fa4dc4)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Nov 6, 2024
…id in Python pickle (pythonGH-126490)

(cherry picked from commit 8fa4dc4)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Nov 6, 2024
…Python pickle (GH-126490) (GH-126514)

(cherry picked from commit 8fa4dc4)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this issue Nov 6, 2024
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 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

1 participant