diff --git a/changes/4684.bugfix.md b/changes/4684.bugfix.md new file mode 100644 index 0000000000..6d15b3c354 --- /dev/null +++ b/changes/4684.bugfix.md @@ -0,0 +1 @@ +`zarr.consolidate_metadata` now picks up arrays that were resized or added inside a nested group that carries its own consolidated metadata. Before, the groups below the first level were listed from the consolidated metadata that they carried instead of from the store. The result kept the old shape of a resized array and missed an array that was added. diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 561a2be8c0..0e3397c09a 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -3691,7 +3691,11 @@ async def _iter_members_deep( if is_group and do_recursion: node = cast("AsyncGroup", node) to_recurse[name] = _iter_members_deep( - node, max_depth=new_depth, skip_keys=skip_keys, semaphore=semaphore + node, + max_depth=new_depth, + skip_keys=skip_keys, + semaphore=semaphore, + use_consolidated_for_children=use_consolidated_for_children, ) for prefix, subgroup_iter in to_recurse.items(): diff --git a/tests/test_metadata/test_consolidated.py b/tests/test_metadata/test_consolidated.py index e6d1f6378a..7b577851ab 100644 --- a/tests/test_metadata/test_consolidated.py +++ b/tests/test_metadata/test_consolidated.py @@ -759,6 +759,26 @@ async def test_use_consolidated_for_children_members( expected = ["b", "b/c"] assert result == expected + async def test_use_consolidated_for_children_members_nested( + self, memory_store: zarr.storage.MemoryStore + ) -> None: + # As the test above, but the child group with consolidated metadata is + # two levels below the group whose members are listed. + + root = await zarr.api.asynchronous.create_group(store=memory_store) + await root.create_group("a/b") + # Consolidate metadata at "a/b" + await zarr.api.asynchronous.consolidate_metadata(memory_store, path="a/b") + + # Add a new group a/b/c, that's not present in the CM at "a/b" + await root.create_group("a/b/c") + + result = sorted( + [x[0] async for x in root.members(max_depth=None, use_consolidated_for_children=False)] + ) + expected = ["a", "a/b", "a/b/c"] + assert result == expected + async def test_absolute_path_for_subgroup(self, memory_store: zarr.storage.MemoryStore) -> None: root = await zarr.api.asynchronous.create_group(store=memory_store) await root.create_group("a/b")