Skip to content

fix: allow opening non-existent ZipStore in read mode#4048

Open
NIK-TIGER-BILL wants to merge 1 commit into
zarr-developers:mainfrom
NIK-TIGER-BILL:fix/issue-2450
Open

fix: allow opening non-existent ZipStore in read mode#4048
NIK-TIGER-BILL wants to merge 1 commit into
zarr-developers:mainfrom
NIK-TIGER-BILL:fix/issue-2450

Conversation

@NIK-TIGER-BILL

Copy link
Copy Markdown
Contributor

Summary

Currently, opening a non-existent ZipStore in mode r fails because zipfile.ZipFile raises an exception when the file does not exist. This is inconsistent with other Store classes which can be opened in r mode without issues.

Changes

  • Handle the case where a ZipStore is opened in r mode but the file does not yet exist.

Testing

  • Added test verifying that a fresh ZipStore can be opened in r mode.

Fixes #2450

Fixes zarr-developers#2450

Signed-off-by: NIK-TIGER-BILL <nik.tiger.bill@github.com>
@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jun 7, 2026
@codecov

codecov Bot commented Jun 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.53%. Comparing base (b9d3964) to head (93b76fd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4048   +/-   ##
=======================================
  Coverage   93.53%   93.53%           
=======================================
  Files          88       88           
  Lines       11894    11897    +3     
=======================================
+ Hits        11125    11128    +3     
  Misses        769      769           
Files with missing lines Coverage Δ
src/zarr/storage/_zip.py 97.72% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b

d-v-b commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

i feel like it's a bit surprising if mode=r has side effects (creating a zip file). This is a special thing for the zipstore because a zip archive exists in some other storage system.

@NIK-TIGER-BILL

Copy link
Copy Markdown
Contributor Author

That is a fair point. I chose creating an empty zip as the least-surprising way to keep the store API consistent — other stores can be opened in r mode even when the backing path does not exist yet, and the caller gets an empty read-only store.

The alternative I considered was to raise a custom FileNotFoundError, but that breaks the uniformity of the Store.open contract. Another option would be to hold a no-op ZipFile-like object internally, but that would require re-implementing parts of zipfile just to avoid the side effect.

I'm happy to switch to a different approach if the maintainers prefer — e.g., raise a clear FileNotFoundError in r mode, or document the side effect explicitly. Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs release notes Automatically applied to PRs which haven't added release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A fresh ZipStore cannot be opened with mode r

2 participants