Skip to content

Dictionary watchers deliver added event before it's guaranteed to be successful leading to possible incosistent state #122208

Closed
@DinoV

Description

@DinoV

Bug report

Bug description:

Currently dictionary watchers deliver the PyDict_EVENT_ADDED event before they have done everything that is necessary to ensure success. If the dictionary requires a resize for insertion to succeed (or a new keys object needs to be allocated from an empty dict) and that fails then the dictionary watcher will have inconsistent state to what's stored in the dictionary. Watchers should only receive the event when the dictionary implementation is guaranteed that it will succeed.

The event can still be delivered before the insertion happens meaning there's no visible change in behavior except for the OOM case.

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions