Skip to content

fix: return None for missing keys in LocalStore batch reads - #4707

Open
zengyuanzhao wants to merge 10 commits into
zarr-developers:mainfrom
zengyuanzhao:fix/localstore-missing-key
Open

zengyuanzhao wants to merge 10 commits into
zarr-developers:mainfrom
zengyuanzhao:fix/localstore-missing-key

Conversation

@zengyuanzhao

@zengyuanzhao zengyuanzhao commented Dec 5, 2026 •

Copy link
Copy Markdown

Summary

Fixes #4706
Refs #2614

While reviewing LocalStore test coverage, I found that the existing batch-read test wrote every key it requested. Adding a missing key between two byte ranges from the same file caused the entire batch to raise FileNotFoundError. With this fix, reading the first two bytes of b"NAME", a missing key, and the last two bytes returns [b"NA", None, b"ME"] in request order.

LocalStore.get_partial_values() still reads concurrently. It consumes the input iterable before scheduling reads, so if iteration fails, the original exception propagates and no reads start.

For reviewers

Please check how the code distinguishes a missing key from an inaccessible file or store.

  • Single and batch reads share a helper that treats directories as missing keys. When a read raises PermissionError, as it can for a directory on Windows, the helper returns None only after confirming the path is a directory. Permission errors on regular files and errors from buffer construction propagate.
  • Batch reads check the root once in a worker thread if any result is None. If an open store’s root is renamed, both writable and read-only stores raise FileNotFoundError with the original root path in filename. Replacing the root with a regular file raises NotADirectoryError. Only an unopened writable store permits an absent root, and the batch read leaves it absent.

Verification at a414136

  • Linux, Python 3.14.10. I ran all 138 LocalStore tests and Ruff 0.17.3 lint and format checks on both changed Python files. All passed. The directory test simulated the Windows PermissionError.
  • Native Windows 11, Python 3.12.13. Codex ran the same 138 tests. All passed. With real directories, Codex verified both root rename cases and confirmed that reading group and group/chunk together returned [None, b"data"].
  • Windows ACLs. Codex used a real ACL to deny read access to a regular file. Synchronous get_sync(), asynchronous get(), and a get_partial_values() batch that also included a readable file all raised PermissionError (errno=13) with filename pointing to the denied file.

Author attestation

Prepared with Codex assistance.

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

@zengyuanzhao
zengyuanzhao marked this pull request as ready for review December 5, 2026 06:12

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.

LocalStore.get_partial_values() fails the entire batch when one key is missing

1 participant