Skip to content

Make Patch pickleable #2498

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

Merged
merged 4 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

## Fixed

- [#2498](https://github.com/plotly/dash/pull/2498) Fix error when caching callbacks which return `Patch` objects by making `Patch` objects picklable
- [#2491](https://github.com/plotly/dash/pull/2491) Fix clientside inline function name not found, fix [#2488](https://github.com/plotly/dash/issues/2488)

## [2.9.2] - 2023-03-29
Expand Down
6 changes: 6 additions & 0 deletions dash/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def __init__(self, location=None, parent=None):
else:
self._operations = []

def __getstate__(self):
return vars(self)

def __setstate__(self, state):
vars(self).update(state)

def __getitem__(self, item):
validate_slice(item)
return Patch(location=self._location + [item], parent=self)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,14 @@ def test_pat019_patch_remove():
"location": [],
"params": {"value": "item"},
}


def test_pat020_patch_pickle():
import pickle

p = Patch()
p["a"] = "a"
data = pickle.dumps(p)
q = pickle.loads(data)

assert patch_to_dict(p) == patch_to_dict(q)