Skip to content

Suppress FileNotFoundError when deleting keys in the obstore adapter #3140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
8 changes: 8 additions & 0 deletions changes/3140.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Suppress `FileNotFoundError` when deleting non-existent keys in the `obstore` adapter.

When writing empty chunks (i.e. chunks where all values are equal to the array's fill value) to a zarr array, zarr
will delete those chunks from the underlying store. For zarr arrays backed by the `obstore` adapter, this will potentially
raise a `FileNotFoundError` if the chunk doesn't already exist.
Since whether or not a delete of a non-existing object raises an error depends on the behavior of the underlying store,
suppressing the error in all cases results in consistent behavior across stores, and is also what `zarr` seems to expect
from the store.
7 changes: 6 additions & 1 deletion src/zarr/storage/_obstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@
import obstore as obs

self._check_writable()
await obs.delete_async(self.store, key)

# Some stores such as local filesystems, GCP and Azure raise an error
# when deleting a non-existent key, while others such as S3 and in-memory do
# not. We suppress the error to make the behavior consistent across all stores
with contextlib.suppress(FileNotFoundError):
await obs.delete_async(self.store, key)

Check warning on line 189 in src/zarr/storage/_obstore.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/storage/_obstore.py#L188-L189

Added lines #L188 - L189 were not covered by tests

@property
def supports_partial_writes(self) -> bool:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_store/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def test_store_init_raises(self) -> None:
with pytest.raises(TypeError):
ObjectStore("path/to/store")

async def test_store_delete_nonexistent_key_does_not_raise(self, store: ObjectStore) -> None:
await store.delete("nonexistent_key")


@pytest.mark.slow_hypothesis
def test_zarr_hierarchy():
Expand Down