Fix ZarrParser crash on S3 directory-marker objects#1055
Open
TomNicholas wants to merge 1 commit into
Open
Conversation
obstore strips the trailing slash from listed S3 object keys, so
build_1d_chunk_mapping's endswith("/") check can never filter out
zero-byte "directory marker" objects (created by e.g. `aws s3 sync`,
`s3fs`, or `boto3.put_object(Key=prefix + "/")`) from the discovered
chunk keys. The marker then fails int() parsing in build_chunk_manifest.
Filter on whether each listed key actually starts with the full
array_chunks_prefix instead: a directory marker is keyed exactly as
the prefix with its trailing slash removed, so it's one character
shorter than any genuine nested chunk key and fails that test
regardless of whether obstore has already stripped its own slash.
Fixes zarr-developers#1052
Co-authored-by: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1055 +/- ##
=======================================
Coverage 90.39% 90.39%
=======================================
Files 37 37
Lines 2248 2249 +1
=======================================
+ Hits 2032 2033 +1
Misses 216 216
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1052.
obstorestrips the trailing slash from listed S3 object keys, sobuild_1d_chunk_mapping'sendswith("/")check can never filter out zero-byte "directory marker" objects (created by e.g.aws s3 sync,s3fs, orboto3.put_object(Key=prefix + "/")) out of the discovered chunk keys. The marker then failsint()parsing inbuild_chunk_manifest, crashing with e.g.ValueError: invalid literal for int() with base 10: 'precip'.This isn't a rare edge case — of 152 real-world public Zarr v2 stores I swept (NOAA/NCAR/weatherbench2 datasets on AWS Open Data), 26 failed with this exact error.
Fix
Filter on whether each listed key actually starts with the full
array_chunks_prefixinstead of relying on the (now ineffective) trailing-slash check. A directory marker is keyed exactly as the prefix with its trailing slash removed, so it's one character shorter than the prefix and can never satisfystartswith(prefix)— this holds regardless of whetherobstorehas already stripped the marker's own trailing slash, so it's robust to the underlying cause rather than papering over one specific symptom.Test plan
test_build_chunk_manifest_ignores_directory_marker_objectinvirtualizarr/tests/test_parsers/test_zarr.py. Since no in-memory or localobstorebackend reproduces the S3-specific slash-stripping quirk itself (writes and lists are both path-normalized consistently for those backends, so a marker written viaMemoryStore.put_asyncnever even collides with a nested-chunk listing), the test fabricates the exact listing shape a real S3 store returns and feeds it tobuild_chunk_manifestdirectly.ValueErroragainst the pre-fix code, and passes after the fix.pytest virtualizarr/tests),ruff check/ruff formatclean,mypyclean on the changed file.s3://noaa-nwm-retrospective-2-1-zarr-pds/precip.zarr), which now opens successfully instead of raising.[This is Claude Code on behalf of TomNicholas]