Skip to content

Commit

Permalink
Strengthen pickling test and fix ZipStore __getstate__() (#2807)
Browse files Browse the repository at this point in the history
* Strenghten serialization test

* Fix ZipStore serialization

* Add changelog bug fix
  • Loading branch information
maxrjones authored Feb 7, 2025
1 parent a52048d commit 57181c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/2807.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pickling for ZipStore
3 changes: 2 additions & 1 deletion src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57181c9

Please sign in to comment.