Skip to content

fix(storage): add _is_open guard in ZipStore.exists to prevent AttributeError#3838

Open
NIK-TIGER-BILL wants to merge 1 commit intozarr-developers:mainfrom
NIK-TIGER-BILL:fix/zipstore-exists-missing-open-check
Open

fix(storage): add _is_open guard in ZipStore.exists to prevent AttributeError#3838
NIK-TIGER-BILL wants to merge 1 commit intozarr-developers:mainfrom
NIK-TIGER-BILL:fix/zipstore-exists-missing-open-check

Conversation

@NIK-TIGER-BILL
Copy link
Copy Markdown

Description

ZipStore.exists() accessed self._lock directly without first checking self._is_open, causing an AttributeError when the store was instantiated but not yet opened.

All other mutating/reading methods in ZipStore (e.g. _get, _set, set, set_if_not_exists, delete) guard access to self._lock with:

if not self._is_open:
    self._sync_open()

exists() was the only method that missed this guard.

Reproduction (before fix)

import zipfile, asyncio
from zarr.storage import ZipStore

with zipfile.ZipFile("/tmp/test.zip", "w") as zf:
    zf.writestr("zarr.json", b"{}")

store = ZipStore("/tmp/test.zip", mode="r")
asyncio.run(store.exists("zarr.json"))
# AttributeError: 'ZipStore' object has no attribute '_lock'

Fix

Added the missing _is_open check at the top of exists(), consistent with all other methods.

Fixes #3588

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

…uteError

ZipStore.exists() did not call self._sync_open() before accessing
self._lock, causing AttributeError when called on an unopened store.

Add the same _is_open check that other ZipStore methods (get, set,
set_if_not_exists, delete) already use.

Also add a regression test that instantiates ZipStore without an
explicit .open() call and verifies exists() works correctly.

Fixes zarr-developers#3588

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 Mar 26, 2026
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.

AttributeError: 'ZipStore' object has no attribute '_lock'

1 participant