Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/zarr/storage/_obstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,14 @@ async def _transform_list_dir(
for path in chain(
list_result["common_prefixes"], map(itemgetter("path"), list_result["objects"])
):
yield _relativize_path(path=path, prefix=prefix)
# Skip entries that exactly match the prefix or are the prefix with a trailing slash.
# These represent the prefix itself rather than children.
if path == prefix or path == f"{prefix}/":
continue
relative = _relativize_path(path=path, prefix=prefix)
if relative == "":
continue
yield relative


class _BoundedRequest(TypedDict):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_store/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ async def test_store_getsize_prefix(self, store: ObjectStore[LocalStore]) -> Non
total_size = await store.getsize_prefix("c")
assert total_size == len(buf) * 2

async def test_list_dir_prefix_object(self, store: ObjectStore[LocalStore]) -> None:
"""list_dir should not raise ValueError when an object keyed like the prefix exists."""
buf = cpu.Buffer.from_bytes(b"\x00")
# Create an object whose key is exactly the prefix with a trailing slash.
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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead assert that result is exactly what we expect, instead of asserting that something we don't expect is not in result?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point — changed to assert result == [] to assert the exact expected result instead of a negative check. Thanks for the feedback!

assert result == []


@pytest.mark.slow_hypothesis
def test_zarr_hierarchy() -> None:
Expand Down
Loading