Skip to content

gh-158126: Avoid creating AttributeError for optional Pickler attribute lookups - #158148

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
lazerg:fix-issue-158126
Oct 22, 2026
Merged

serhiy-storchaka merged 1 commit into
python:mainfrom
lazerg:fix-issue-158126

Conversation

@lazerg

@lazerg lazerg commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Since Pickler got its own tp_getattro for persistent_id, PyObject_GetOptionalAttr() no longer takes its fast path for it, so every dump() builds and clears an AttributeError when it looks up reducer_override, and __init__() does the same for dispatch_table. When the type still uses Pickler_getattr, this now calls _PyObject_GenericGetAttrWithDict() with suppress=1 directly. Pickler_getattr only special-cases persistent_id, so the result is the same. Subclasses that override __getattr__ or __getattribute__ keep the old path.

Fixes #158126

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) October 22, 2026 14:34
@serhiy-storchaka
serhiy-storchaka merged commit e60a9da into python:main Oct 22, 2026
65 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @lazerg for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160251 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 22, 2026
@bedevere-app

bedevere-app Bot commented Oct 22, 2026

Copy link
Copy Markdown

GH-160252 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 22, 2026
serhiy-storchaka pushed a commit that referenced this pull request Oct 22, 2026
…attribute lookups (GH-158148) (GH-160252)

(cherry picked from commit e60a9da)

Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Oct 22, 2026
…attribute lookups (GH-158148) (GH-160251)

(cherry picked from commit e60a9da)

Co-authored-by: Lazizbek Ergashev <lazerg2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pickle.dumps() creates and discards an AttributeError on every call since 3.13.1

2 participants