Skip to content

Commit

Permalink
Merge pull request #2498 from joouha/pickleable-patch
Browse files Browse the repository at this point in the history
Make `Patch` pickleable
  • Loading branch information
T4rk1n authored Apr 11, 2023
2 parents 37d7c30 + 2e65eef commit 093b559
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
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)

0 comments on commit 093b559

Please sign in to comment.