Skip to content
Closed
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
5 changes: 5 additions & 0 deletions changes/3773.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fix divergent behavior between `MemoryStore` and `LocalStore` `list_prefix` methods.

Both stores now consistently use string prefix matching (checking if keys start with the given prefix string),
rather than `LocalStore` treating the prefix as a filesystem directory path. This ensures consistent
behavior across different store implementations and aligns with the documented behavior of `list_prefix`.
9 changes: 6 additions & 3 deletions src/zarr/storage/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,14 @@ async def list(self) -> AsyncIterator[str]:

async def list_prefix(self, prefix: str) -> AsyncIterator[str]:
# docstring inherited
# Use string prefix matching to be consistent with MemoryStore behavior.
# The prefix should match keys as strings, not as filesystem paths.
to_strip = self.root.as_posix() + "/"
prefix = prefix.rstrip("/")
for p in (self.root / prefix).rglob("*"):
for p in list(self.root.rglob("*")):
if p.is_file():
yield p.as_posix().replace(to_strip, "")
key = p.as_posix().replace(to_strip, "")
if key.startswith(prefix):
yield key

async def list_dir(self, prefix: str) -> AsyncIterator[str]:
# docstring inherited
Expand Down
Loading