Skip to content

Commit f78cfd9

Browse files
committed
TypeError if consolidate_metadata called on non-consolidating stores
1 parent f0f0c2c commit f78cfd9

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

src/zarr/api/asynchronous.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def consolidate_metadata(
175175
176176
Upon completion, the metadata of the root node in the Zarr hierarchy will be
177177
updated to include all the metadata of child nodes. For Stores that prefer
178-
not to use consolidated metadata, this operation does nothing.
178+
not to use consolidated metadata, this operation raises a ``TypeError``.
179179
180180
Parameters
181181
----------
@@ -201,15 +201,13 @@ async def consolidate_metadata(
201201
"""
202202
store_path = await make_store_path(store, path=path)
203203

204-
group = await AsyncGroup.open(store_path, zarr_format=zarr_format, use_consolidated=False)
205204
if not store_path.store.supports_consolidated_metadata:
206205
store_name = type(store_path.store).__name__
207-
warnings.warn(
208-
f"The Zarr Store in use ({store_name}) doesn't support consolidated metadata. Ignoring.",
209-
stacklevel=1,
206+
raise TypeError(
207+
f"The Zarr Store in use ({store_name}) doesn't support consolidated metadata",
210208
)
211-
return group
212209

210+
group = await AsyncGroup.open(store_path, zarr_format=zarr_format, use_consolidated=False)
213211
group.store_path.store._check_writable()
214212

215213
members_metadata = {

tests/test_metadata/test_consolidated.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
open,
1818
open_consolidated,
1919
)
20-
from zarr.core.buffer import Buffer, cpu, default_buffer_prototype
20+
from zarr.core.buffer import cpu, default_buffer_prototype
2121
from zarr.core.group import ConsolidatedMetadata, GroupMetadata
2222
from zarr.core.metadata import ArrayV3Metadata
2323
from zarr.core.metadata.v2 import ArrayV2Metadata
2424
from zarr.storage import StorePath
2525

2626
if TYPE_CHECKING:
27-
from zarr.abc.store import ByteRequest, Store
27+
from zarr.abc.store import Store
2828
from zarr.core.common import ZarrFormat
2929

3030

@@ -661,22 +661,14 @@ def supports_consolidated_metadata(self) -> bool:
661661
return False
662662

663663

664-
async def test_consolidate_metadata_is_noop_for_self_consolidating_stores():
664+
async def test_consolidate_metadata_raises_for_self_consolidating_stores():
665665
"""Verify calling consolidate_metadata on a non supporting stores does nothing"""
666666

667667
memory_store = NonConsolidatedStore()
668668
root = await zarr.api.asynchronous.create_group(store=memory_store)
669669
await root.create_group("a/b")
670670

671-
# now we monkey patch the store so it raises if `Store.set` is called
672-
async def set_raises(self, value: Buffer, byte_range: ByteRequest | None = None) -> None:
673-
raise ValueError("consolidated metadata called")
674-
675-
memory_store.set = set_raises
676-
677-
with pytest.warns(UserWarning, match="doesn't support consolidated metadata"):
678-
# consolidate_metadata would call `set` if the store supported consolidated metadata
679-
# if this doesn't raise, it means consolidate_metadata is NOOP
671+
with pytest.raises(TypeError, match="doesn't support consolidated metadata"):
680672
await zarr.api.asynchronous.consolidate_metadata(memory_store)
681673

682674

0 commit comments

Comments
 (0)