diff --git a/changes/2807.bugfix.rst b/changes/2807.bugfix.rst new file mode 100644 index 0000000000..ae0eb2f6ac --- /dev/null +++ b/changes/2807.bugfix.rst @@ -0,0 +1 @@ +Fix pickling for ZipStore diff --git a/src/zarr/storage/_zip.py b/src/zarr/storage/_zip.py index bf8f9900b9..51bb702c27 100644 --- a/src/zarr/storage/_zip.py +++ b/src/zarr/storage/_zip.py @@ -108,7 +108,8 @@ async def _open(self) -> None: self._sync_open() def __getstate__(self) -> dict[str, Any]: - state = self.__dict__ + # We need a copy to not modify the state of the original store + state = self.__dict__.copy() for attr in ["_zf", "_lock"]: state.pop(attr, None) return state diff --git a/src/zarr/testing/store.py b/src/zarr/testing/store.py index 00427f6a0e..112f6261e9 100644 --- a/src/zarr/testing/store.py +++ b/src/zarr/testing/store.py @@ -99,10 +99,16 @@ def test_store_eq(self, store: S, store_kwargs: dict[str, Any]) -> None: store2 = self.store_cls(**store_kwargs) assert store == store2 - def test_serializable_store(self, store: S) -> None: + async def test_serializable_store(self, store: S) -> None: new_store: S = pickle.loads(pickle.dumps(store)) assert new_store == store assert new_store.read_only == store.read_only + # quickly roundtrip data to a key to test that new store works + data_buf = self.buffer_cls.from_bytes(b"\x01\x02\x03\x04") + key = "foo" + await store.set(key, data_buf) + observed = await store.get(key, prototype=default_buffer_prototype()) + assert_bytes_equal(observed, data_buf) def test_store_read_only(self, store: S) -> None: assert not store.read_only