Skip to content

Python dictionary watchers no longer trigger when an object's attributes change #125608

Closed
@colesbury

Description

@colesbury

Bug report

Here's an example function using test_capi/test_watchers.py that passes in 3.12, but fails in 3.13 and 3.14:

    def test_watch_obj_dict(self):
        o = MyClass()
        with self.watcher() as wid:
            self.watch(wid, o.__dict__)
            o.foo = "bar"
            self.assert_events(["new:foo:bar"])  # fails in 3.13+ 

The dictionary watcher doesn't fire in 3.13+ even though the o.__dict__ changes when o.foo is set to "bar". The problem is specific to inline values -- our code paths for inline values do not trigger dictionary watcher events. If the object does not use inline values, then the watcher events fire as expected.

This is a problem for PyTorch Dyanmo because it uses dictionary watchers for compiler guards.

cc @williamwen42 @markshannon

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions