Skip to content

Able to delete group even when opened as readonly #3147

Closed

Description

@TomNicholas

Zarr version

v3.0.8

Numcodecs version

0.16.1

Python Version

3.12.4

Operating System

linux

Installation

pip

Description

I was not expecting to be able to delete a group when opening from the store using mode='r'.

Steps to reproduce

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",
# ]
# ///

import zarr

store = zarr.storage.MemoryStore()
root = zarr.create_group(store=store)
foo = root.create_group('foo')
bar = root.create_group('bar')
root.members()
# (('foo', <Group memory://139839476802624/foo>),
# ('bar', <Group memory://139839476802624/bar>))

# re-open root group in a supposedly readonly state
root_readonly = zarr.open_group(store, path='/', mode='r')

# delete a child group
del root_readonly['foo']

root_readonly.members()
# (('bar', <Group memory://139839476802624/bar>),)

zarr.print_debug_info()
platform: Linux-5.10.220-209.869.amzn2.x86_64-x86_64-with-glibc2.35
python: 3.12.4
zarr: 3.0.8

**Required dependencies:**
packaging: 24.1
numpy: 1.26.4
numcodecs: 0.16.1
typing_extensions: 4.12.2
donfig: 0.8.1.post1

**Optional dependencies:**
botocore: 1.34.106
fsspec: 2024.6.0
numcodecs: 0.16.1
s3fs: 2024.6.0
gcsfs: 2024.6.0
rich: 13.7.1

**Not Installed:**
cupy-cuda12x
universal-pathlib
obstore

Additional output

No response

Activity

  1. added
    bugPotential issues with the zarr-python library
    on Jun 18, 2025
  2. d-v-b commented on Jun 18, 2025

    @d-v-b
    Contributor

    at the moment mode=r for arrays and groups is a placebo. This is related to #3068 (comment)

  3. maxrjones commented on Jun 18, 2025

    @maxrjones
    Member

    Since #3068 (currently unreleased), zarr.open_group(store=writeable_store, read_only=True) errors:

    Store is not read-only but mode is 'r'
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/storage/_common.py", line 90, in open
        raise ValueError(f"Store is not read-only but mode is '{mode}'")
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/storage/_common.py", line 337, in make_store_path
        result = await StorePath.open(store, path=path_normalized, mode=mode)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/api/asynchronous.py", line 837, in open_group
        store_path = await make_store_path(store, mode=mode, storage_options=storage_options, path=path)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/core/sync.py", line 119, in _runner
        return await coro
               ^^^^^^^^^^
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/core/sync.py", line 163, in sync
        raise return_result
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/api/synchronous.py", line 535, in open_group
                async_api.open_group(
        ...<14 lines>...
        
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/src/zarr/_compat.py", line 43, in inner_f
        return f(*args, **kwargs)
      File "/Users/max/Documents/Code/zarr-developers/zarr-python/.vscode/del-group.py", line 12, in <module>
        root_readonly = zarr.open_group(store, path='/', mode='r')
      File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/runpy.py", line 88, in _run_code
        exec(code, run_globals)
      File "/opt/homebrew/Cellar/[email protected]/3.13.5/Frameworks/Python.framework/Versions/3.13/lib/python3.13/runpy.py", line 198, in _run_module_as_main (Current frame)
        return _run_code(code, main_globals, None,
    ValueError: Store is not read-only but mode is 'r'
    

    with the proposal in #3068 (comment) you would instead get an error on del root_readonly['foo'].

  4. TomNicholas commented on Jun 18, 2025

    @TomNicholas
    MemberAuthor

    with the proposal in #3068 (comment) you would instead get an error on del root_readonly['foo'].

    I don't have much context, but that sounds more intuitive to me.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions