Skip to content

Commit 57181c9

Browse files
authored
Strengthen pickling test and fix ZipStore __getstate__() (#2807)
* Strenghten serialization test * Fix ZipStore serialization * Add changelog bug fix
1 parent a52048d commit 57181c9

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

changes/2807.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix pickling for ZipStore

src/zarr/storage/_zip.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ async def _open(self) -> None:
108108
self._sync_open()
109109

110110
def __getstate__(self) -> dict[str, Any]:
111-
state = self.__dict__
111+
# We need a copy to not modify the state of the original store
112+
state = self.__dict__.copy()
112113
for attr in ["_zf", "_lock"]:
113114
state.pop(attr, None)
114115
return state

src/zarr/testing/store.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,16 @@ def test_store_eq(self, store: S, store_kwargs: dict[str, Any]) -> None:
9999
store2 = self.store_cls(**store_kwargs)
100100
assert store == store2
101101

102-
def test_serializable_store(self, store: S) -> None:
102+
async def test_serializable_store(self, store: S) -> None:
103103
new_store: S = pickle.loads(pickle.dumps(store))
104104
assert new_store == store
105105
assert new_store.read_only == store.read_only
106+
# quickly roundtrip data to a key to test that new store works
107+
data_buf = self.buffer_cls.from_bytes(b"\x01\x02\x03\x04")
108+
key = "foo"
109+
await store.set(key, data_buf)
110+
observed = await store.get(key, prototype=default_buffer_prototype())
111+
assert_bytes_equal(observed, data_buf)
106112

107113
def test_store_read_only(self, store: S) -> None:
108114
assert not store.read_only

0 commit comments

Comments
 (0)