Skip to content

Commit edd8a68

Browse files
jhammanrabernat
andauthored
fix for readonly error in _normalize_store_arg_v3 (#1383)
* fix for readonly error in _normalize_store_arg_v3 * add test * add release note --------- Co-authored-by: Ryan Abernathey <[email protected]>
1 parent e1e5561 commit edd8a68

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
rev: v2.2.2
1919
hooks:
2020
- id: codespell
21-
args: ["-L", "ba,ihs,kake,nd,noe,nwo,te", "-S", "fixture"]
21+
args: ["-L", "ba,ihs,kake,nd,noe,nwo,te,fo", "-S", "fixture"]
2222
- repo: https://github.com/pre-commit/pre-commit-hooks
2323
rev: v4.4.0
2424
hooks:

docs/release.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Bug fixes
4141
* Fix the conda-forge error. Read :issue:`1347` for detailed info.
4242
By :user:`Josh Moore <joshmoore>` :issue:`1364` and :issue:`1367`.
4343

44+
* Fix ``ReadOnlyError`` when opening V3 store via fsspec reference file system.
45+
By :user:`Joe Hamman <jhamman>` :issue:`1383`.
46+
4447
.. _release_2.14.2:
4548

4649
2.14.2

zarr/_storage/v3.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,10 @@ def _normalize_store_arg_v3(store: Any, storage_options=None, mode="r") -> BaseS
618618
# return N5StoreV3(store)
619619
else:
620620
store = DirectoryStoreV3(store)
621-
# add default zarr.json metadata
622-
store['zarr.json'] = store._metadata_class.encode_hierarchy_metadata(None)
623-
return store
624621
else:
625622
store = StoreV3._ensure_store(store)
626-
if 'zarr.json' not in store:
627-
# add default zarr.json metadata
628-
store['zarr.json'] = store._metadata_class.encode_hierarchy_metadata(None)
623+
624+
if 'zarr.json' not in store:
625+
# add default zarr.json metadata
626+
store['zarr.json'] = store._metadata_class.encode_hierarchy_metadata(None)
629627
return store

zarr/tests/test_storage_v3.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,16 @@ def test_normalize_store_arg_v3(tmpdir):
596596
store = normalize_store_arg(fsspec.get_mapper("file://" + path), zarr_version=3)
597597
assert isinstance(store, FSStoreV3)
598598

599+
# regression for https://github.com/zarr-developers/zarr-python/issues/1382
600+
# contents of zarr.json are not important for this test
601+
out = {"version": 1, "refs": {"zarr.json": "{...}"}}
602+
store = normalize_store_arg(
603+
"reference://",
604+
storage_options={"fo": out, "remote_protocol": "memory"},
605+
zarr_version=3
606+
)
607+
assert isinstance(store, FSStoreV3)
608+
599609
fn = tmpdir.join('store.n5')
600610
with pytest.raises(NotImplementedError):
601611
normalize_store_arg(str(fn), zarr_version=3, mode='w')

0 commit comments

Comments
 (0)