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
1 change: 1 addition & 0 deletions changes/3977.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix flaky stateful test bookkeeping when `delete_dir` matches string prefixes instead of true directory descendants. Previously a path such as `6/faNT…` could be incorrectly removed when deleting `6/f`. (See [issue #3977](https://github.com/zarr-developers/zarr-python/issues/3977).)
2 changes: 1 addition & 1 deletion src/zarr/testing/stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def delete_dir(self, data: DataObject) -> None:

matches = set()
for node in self.all_groups | self.all_arrays:
if node.startswith(path):
if node == path or node.startswith(path + "/"):
matches.add(node)
self.all_groups = self.all_groups - matches
self.all_arrays = self.all_arrays - matches
Expand Down
22 changes: 22 additions & 0 deletions tests/test_store/test_stateful.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,25 @@ def mk_test_instance_sync() -> ZarrStoreStateMachine:
# But LocalStore, directories can hang around even after a key is delete-d.
pytest.skip(reason="Test isn't suitable for LocalStore.")
run_state_machine_as_test(mk_test_instance_sync) # type: ignore[no-untyped-call]


def test_delete_dir_prefix_matching() -> None:
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.

let's delete this; it's not neeed

"""Regression test for delete_dir prefix matching bug (GH#3977).

Verifies that delete_dir bookkeeping only removes exact path matches
and true descendants, not unrelated nodes that merely share a string
prefix (e.g. ``6/faNT…`` must NOT be deleted when removing ``6/f``).
"""
all_groups = {"6/f", "6/faNT7p7jvJsO3_C._HYi", "other"}
all_arrays = {"6/f/child", "6/other"}
path = "6/f"

matches = set()
for node in all_groups | all_arrays:
if node == path or node.startswith(path + "/"):
matches.add(node)

assert matches == {"6/f", "6/f/child"}
assert "6/faNT7p7jvJsO3_C._HYi" not in matches
assert "other" not in matches
assert "6/other" not in matches
Loading