fix: handle ObjectStore.list_dir when prefix-like object exists#4038
Open
NIK-TIGER-BILL wants to merge 2 commits into
Open
fix: handle ObjectStore.list_dir when prefix-like object exists#4038NIK-TIGER-BILL wants to merge 2 commits into
NIK-TIGER-BILL wants to merge 2 commits into
Conversation
When an object keyed exactly like the prefix (e.g., "g/" when prefix is "g") exists, list_dir would raise ValueError or yield an empty string because _relativize_path expects the path to start with prefix + "/". This commit filters out entries that exactly match the prefix or are the prefix with a trailing slash, preventing both the error and the empty string yield. Fixes zarr-developers#4032 Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4038 +/- ##
==========================================
- Coverage 93.55% 93.52% -0.04%
==========================================
Files 88 88
Lines 11896 11899 +3
==========================================
- Hits 11129 11128 -1
- Misses 767 771 +4
🚀 New features to boost your workflow:
|
d-v-b
reviewed
Jun 5, 2026
| await self.set(store, "g/", buf) | ||
| # list_dir("g") should not raise even though "g/" looks like the prefix itself. | ||
| result = [k async for k in store.list_dir("g")] | ||
| # The entry should not appear as an empty string or raise. |
Contributor
There was a problem hiding this comment.
can we instead assert that result is exactly what we expect, instead of asserting that something we don't expect is not in result?
Contributor
Author
There was a problem hiding this comment.
Good point — changed to assert result == [] to assert the exact expected result instead of a negative check. Thanks for the feedback!
…r test Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
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.
This PR fixes #4032 by filtering out entries that exactly match the prefix (or the prefix with a trailing slash) in
_transform_list_dir.Previously, if an object keyed exactly like the prefix existed (e.g.,
"g/"when listing"g"),_relativize_pathwould either raiseValueErroror yield an empty string, because it expects paths to start withprefix + "/".Changes
_transform_list_dir, skip entries wherepath == prefixorpath == prefix + "/".Tests
test_list_dir_prefix_objectto verify thatlist_dir("g")does not raise when an object keyed"g/"exists.PR Checklist
git commit -s).