Skip to content
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

Raise an exception for previously set key #2558

Closed

Conversation

maxrjones
Copy link
Member

I think this tests was not correctly checking the behavior because the data at k was previously set, so calling set_if_not_exists on that same key should actually raise an exception. The behavior for obstore in #1661 and kylebarron#3 seem correct, in contrast to the fsspec-based stores which now fail on this test.

src/zarr/testing/store.py Outdated Show resolved Hide resolved
@@ -319,8 +319,9 @@ async def test_set_if_not_exists(self, store: S) -> None:
data_buf = self.buffer_cls.from_bytes(b"0000")
await self.set(store, key, data_buf)

new = self.buffer_cls.from_bytes(b"1111")
await store.set_if_not_exists("k", new) # no error
with pytest.raises(Exception):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we be more specific about the exception? Ideally we would match the type and the error message

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure how to manage matching the type with optional dependencies. Obstore raises its AlreadyExistsError and fsspec raises its FileExistsError. One option is to put this as NotImplemented in the base test class and require the individual stores to implement it in their tests, but that seems non-ideal. Do you have advice?

Matching the error message would be easier because we wouldn't need to import those errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not simple to get more specific than Exception than I think it's OK to leave it as-is, and i can open an issue about how we could make this particular test more specific 😄

@maxrjones
Copy link
Member Author

maxrjones commented Dec 14, 2024

@d-v-b when looking into what exceptions fsspec raises, I noticed that fsspec's internal code comments and the docs lists exclusive write as experimental and risky. Should we warn about this in the Zarr docs?

@d-v-b
Copy link
Contributor

d-v-b commented Dec 14, 2024

@martindurant what do you think?

@jhamman
Copy link
Member

jhamman commented Dec 15, 2024

so calling set_if_not_exists on that same key should actually raise an exception.

I don't know if this is the behavior we want actually. The application in Zarr that relies on this method is to set an empty group metadata object if it doesn't exist yet. If it does, the desired behavior is to move on.

One way to move forward is to catch this error in the Obstore Store and then move on.

@maxrjones
Copy link
Member Author

so calling set_if_not_exists on that same key should actually raise an exception.

I don't know if this is the behavior we want actually. The application in Zarr that relies on this method is to set an empty group metadata object if it doesn't exist yet. If it does, the desired behavior is to move on.

One way to move forward is to catch this error in the Obstore Store and then move on.

Thanks Joe, that makes sense now. I'll follow your recommendation to suggest a change within ObjectStore instead

@maxrjones maxrjones closed this Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants