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

Merged
merged 7 commits into from
Jun 25, 2025
Merged
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.
8 changes: 7 additions & 1 deletion src/zarr/storage/_obstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@
import obstore as obs

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

# Some obstore 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 obstore
# stores. This is also in line with the behavior of the other Zarr store adapters.
with contextlib.suppress(FileNotFoundError):
await obs.delete_async(self.store, key)

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

View check run for this annotation

Codecov / codecov/patch

src/zarr/storage/_obstore.py#L196-L197

Added lines #L196 - L197 were not covered by tests

@property
def supports_partial_writes(self) -> bool:
Expand Down
5 changes: 5 additions & 0 deletions src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@
assert not await store.exists("foo/zarr.json")
assert not await store.exists("foo/c/0")

async def test_delete_nonexistent_key_does_not_raise(self, store: S) -> None:
if not store.supports_deletes:
pytest.skip("store does not support deletes")

Check warning on line 406 in src/zarr/testing/store.py

View check run for this annotation

Codecov / codecov/patch

src/zarr/testing/store.py#L406

Added line #L406 was not covered by tests
await store.delete("nonexistent_key")

async def test_is_empty(self, store: S) -> None:
assert await store.is_empty("")
await self.set(
Expand Down