Skip to content

Backport PR #3140 on branch 3.0.9 (Suppress FileNotFoundError when deleting keys in the obstore adapter) #3180

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
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 @@ -181,7 +181,13 @@ async def delete(self, key: str) -> None:
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)

@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 @@ -349,6 +349,11 @@ async def test_delete_dir(self, store: S) -> None:
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")
await store.delete("nonexistent_key")

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