Skip to content
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
2 changes: 2 additions & 0 deletions changes/2762.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed ZipStore to make sure the correct attributes are saved when instances are pickled.
This fixes a previous bug that prevent using ZipStore with a ProcessPoolExecutor.
13 changes: 8 additions & 5 deletions src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ def _sync_open(self) -> None:
async def _open(self) -> None:
self._sync_open()

def __getstate__(self) -> tuple[Path, ZipStoreAccessModeLiteral, int, bool]:
return self.path, self._zmode, self.compression, self.allowZip64

def __setstate__(self, state: Any) -> None:
self.path, self._zmode, self.compression, self.allowZip64 = state
def __getstate__(self) -> dict[str, Any]:
state = self.__dict__
for attr in ["_zf", "_lock"]:
state.pop(attr, None)
return state

def __setstate__(self, state: dict[str, Any]) -> None:
self.__dict__ = state
self._is_open = False
self._sync_open()

Expand Down
5 changes: 3 additions & 2 deletions src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def test_store_eq(self, store: S, store_kwargs: dict[str, Any]) -> None:
assert store == store2

def test_serializable_store(self, store: S) -> None:
foo = pickle.dumps(store)
assert pickle.loads(foo) == store
new_store: S = pickle.loads(pickle.dumps(store))
assert new_store == store
assert new_store.read_only == store.read_only

def test_store_read_only(self, store: S) -> None:
assert not store.read_only
Expand Down
Loading