Skip to content

Commit afd95d9

Browse files
author
Claude Subagent
committed
fix zarr-developers#3773: Fix divergent behavior between MemoryStore and LocalStore list_prefix
1 parent b6d3ae2 commit afd95d9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

changes/3773.bugfix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix divergent behavior between `MemoryStore` and `LocalStore` `list_prefix` methods.
2+
3+
Both stores now consistently use string prefix matching (checking if keys start with the given prefix string),
4+
rather than `LocalStore` treating the prefix as a filesystem directory path. This ensures consistent
5+
behavior across different store implementations and aligns with the documented behavior of `list_prefix`.

src/zarr/storage/_local.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,14 @@ async def list(self) -> AsyncIterator[str]:
290290

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

299302
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
300303
# docstring inherited

0 commit comments

Comments
 (0)