You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d8c07e1
Browse filesBrowse the repository at this point in the historyBrowse files
fix(api): validate a new node before deleting the existing one (#4410)
* fix: validate a new node before overwriting the existing one
Opening or creating a node with mode="w" or overwrite=True deleted the
existing node before the new one was validated, so an invalid argument
destroyed the existing data and created nothing. For example,
zarr.open(store, mode="w", config=...) on an existing array erased the
store and then raised TypeError from open_group.
Two deletion points ran too early:
- make_store_path(mode="w") erased the path before dispatch in open,
open_array, open_group, create and save_array. These now build the
store path with mode "a" and create the node with overwrite=True.
- overwrite=True deleted the node before its metadata was built in
AsyncArray._create_v2/_create_v3, init_array and AsyncGroup.from_store.
save_new_metadata now encodes the metadata first, then deletes, then
writes.
save_group checks its arguments before erasing the path.
Assisted-by: ClaudeCode:claude-opus-5-5
* docs(changes): add fragment for #4410
Assisted-by: ClaudeCode:claude-opus-5-5
* fix(storage): let node creation own the mode "w" erase
`StorePath.open(mode="w")` no longer deletes the keys under the path. The
node created there replaces them through `save_new_metadata(overwrite=True)`,
once its metadata is valid, so the API functions pass their mode through
unchanged and `_deferred_overwrite_mode` is gone. A read-only store refused
with mode "w" names that mode again in its error.
`save_group` resolves every array's data type before the group is replaced,
and replaces it explicitly with `AsyncGroup.from_store(overwrite=True)`.
The docstrings of `open`, `open_group` and `create` state that a store which
cannot delete keys raises instead of replacing an existing node; the tests
pin that contract over `ZipStore`, seed the overwrite tests with a group that
has children, and cover the read-only error and the `save_group` dtype path.
Assisted-by: ClaudeCode:claude-fable-5-1
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Opening or creating an array or group with `mode="w"` or `overwrite=True` no longer deletes the existing node when the call fails. Previously the existing node was deleted before the new one was validated, so an invalid argument (for example `zarr.open(store, mode="w", config=...)`, an invalid `fill_value`, attributes that are not JSON, or an array `zarr.save_group` cannot store) destroyed the existing data and created nothing. Deletion now belongs to node creation: `StorePath.open(mode="w")` no longer erases the keys under the path, and the node written there replaces them once its metadata is valid. On a store that cannot delete keys, such as `ZipStore`, `mode="w"` creates the node when the path is empty and raises `ContainsArrayError` or `ContainsGroupError` when a node already exists, instead of `NotImplementedError`.
0 commit comments