Skip to content

fix(group): make consolidate_metadata pick up changes in nested groups - #4684

Open
h-mayorquin wants to merge 2 commits into
zarr-developers:mainfrom
h-mayorquin:forward_use_consolidated_for_children
Open

h-mayorquin wants to merge 2 commits into
zarr-developers:mainfrom
h-mayorquin:forward_use_consolidated_for_children

Conversation

@h-mayorquin

@h-mayorquin h-mayorquin commented Dec 1, 2026 •

Copy link
Copy Markdown

Summary

I work on the NWB ecosystem (Neurodata Without Borders), a data standard for neurophysiology and the software around it. NWB is built on HDMF, a package to specify data models and to read and write them in different storage backends. There are two backends, HDF5 and Zarr, and the Zarr one is hdmf-zarr built on zarr-python. One thing that we support is opening a file that already exists and adding to it, for example new rows in the table of electrodes. I found that when the file is in Zarr the write finishes without an error but the new rows are missing when the file is read back.

The following is a reproduction in pure zarr of the same error. table stands for the table of electrodes, the append for the new rows and the attribute update for what hdmf-zarr does on every write:

import numpy as np
import zarr

store = zarr.storage.MemoryStore()
root = zarr.create_group(store)
root.create_array("general/table/column", shape=(2,), dtype="int64")
zarr.consolidate_metadata(store)

# Open through the consolidated metadata, resize an array in a nested group
# and update the attributes of that group
root = zarr.open_consolidated(store)
table = root["general/table"]
table["column"].append(np.array([2, 3]))
table.attrs["colnames"] = ["column"]

zarr.consolidate_metadata(store)
# The array has the new shape in its own metadata
print(zarr.open_group(store, use_consolidated=False)["general/table/column"].shape)  # (4,)
# But the consolidated metadata keeps the old one
print(zarr.open_consolidated(store)["general/table/column"].shape)  # (2,)

After the attribute update consolidate_metadata does not pick up what happens inside table anymore. An array that is resized there keeps its old shape in the consolidated metadata and one that is added is missing from it, however many times it is called. This only happens when the group is nested inside another group. If table is directly under the root the second line prints (4,).

The cause is that consolidate_metadata lists the members with use_consolidated_for_children=False but the option is not passed down when the listing goes into a child group. So table is listed from the consolidated metadata that it carries. It carries one as updating its attributes saves it with the consolidated metadata that it was opened with.

This PR makes consolidate_metadata read the groups from the store at every depth (it passes the option in the recursive call). I added a test for a group that is nested one level deeper than in the existing test as that one only covers direct children. The same line is part of #4343 by @d-v-b.

For reviewers

What I want you to look at is whether it is OK to separate this from the original PR (#4343). That one is in draft and I am unsure about its scope and extent. So I am opening this one as this particular fix is important for us.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Dec 1, 2026
@github-actions github-actions Bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant