Skip to content

Commit bff2a7d

Browse files
committed
Add info about read_only
1 parent 3219f40 commit bff2a7d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

docs/developers/store_permissions.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,28 @@ Zarr Python has two data models (`Array` and `Group`) and one storage model (`St
1010

1111
## Store properties related to permissions
1212

13-
### `supports_writes`
13+
### Instance properties
14+
15+
#### `read_only`
16+
17+
The `read_only` property indicates whether store *instances* should allow `set`, `delete` operations and their permutations. If `read_only` is `True`, then the store should reject any write or delete operations. If `read_only` is `False`, then the store should allow write and delete operations. The property is tested by `Store` methods by calling `self._check_writable()`, which raises a `ValueError` if the store's `read_only` property is true.
18+
19+
The `read_only` property is one of the most likely places to encounter a bug for a few reasons:
20+
21+
- `Store` implementations must remember to call `super.__init__(read_only=read_only)` in their `__init__` method to set the `read_only` property correctly.
22+
- `Store` implementations must remember to call `self._check_writable()` in their `set` and `delete` methods to enforce the `read_only` property.
23+
- `Array` and `Group` classes must remember to check alignment with the `read_only` property of the store with any `overwrite` arguments.
24+
- Top level API functions must remember to check the `read_only` property of the store when creating new arrays or groups. This is complicated by the API functions using "mode" semantics like "w", "r", "a", etc., which are not directly related to the `read_only` property. Each function typically has its own logic for matching mode semntics to the `read_only` property of the store.
25+
26+
This is one of the most likely place to encounter a bug where a `read_only` property is not respected because implementations must remember to call `self._check_writable()` when implementing `store.set()`, which is not implemented in the `Store` abstract base class.
27+
28+
The Zarr spec does not seem to define how APIs should constrain write/delete permissions at the instance level.
29+
30+
### Class properties
31+
32+
The Zarr spec provides distinctions between readable, writeable, and listable stores, but does not define how to distinguish between these groups of store operations. The Zarr Python library has adopted the following properties to distinguish between these groups of operations at the *class* level, which are used by the `Store` abstract base class and the testing framework.
33+
34+
#### `supports_writes`
1435

1536
This is a property of the *class* that should indicate whether the store implements the following methods:
1637

@@ -19,7 +40,7 @@ This is a property of the *class* that should indicate whether the store impleme
1940

2041
`supports_writes` is primarily used by tests to determine the expected result of write operations. It is not used by the library to enforce permissions.
2142

22-
### `supports_partial_writes`
43+
#### `supports_partial_writes`
2344

2445
The purpose of this property of the *class* is currently ambiguous.
2546

@@ -31,7 +52,7 @@ But the `FsspecStore` class does not implement this method, but it does have `su
3152

3253
Another interpretation is that it indicates whether the store supports a `byte_range` argument in the `set` method.
3354

34-
### `supports_deletes`
55+
#### `supports_deletes`
3556

3657
This is a property of the *class* that should indicate whether the store implements the following methods:
3758

@@ -46,7 +67,7 @@ The `supports_deletes` property is also used by the testing framework to determi
4667
!!! note
4768
Store implementations are agnostic to the Zarr data model. They will delete everything under the given prefix, regardless of whether it is an array, group, or unrelated to the Zarr store.
4869

49-
### `supports_listing`
70+
#### `supports_listing`
5071

5172
This is a property of the *class* that should indicate whether the store implements the following method:
5273

0 commit comments

Comments
 (0)