Skip to content

Commit 025de4f

Browse files
committed
fix(zarr-metadata): a field whose configuration is not an object is still claimed by its name
`resolve` read a field whose configuration was not an object as claimed by nothing, although its name names a definition, so the codec order was judged without it: `[{"name": "gzip", "configuration": 5}, "bytes"]` drew no problem for the gzip before the bytes codec. The field keeps the definition its name names, unread. Assisted-by: ClaudeCode:claude-opus-5-5
1 parent f004256 commit 025de4f

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎packages/zarr-metadata/src/zarr_metadata/v3/_definition.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,9 +985,13 @@ def _read(
985985
data: JSONValue, kind: type[Definition[Any]], context: Context, loc: Loc
986986
) -> tuple[Resolved[Definition[Any]], Problems]:
987987
name, given, malformed = named_configuration(data)
988-
if name is None or len(malformed) != 0:
988+
if name is None:
989989
return Resolved(data, "invalid", None, None), ()
990990
definition = context.claimant(kind, name)
991+
if len(malformed) != 0:
992+
# A configuration that is not an object, which the envelope's
993+
# problems say; the name still says what claims the field.
994+
return Resolved(data, "invalid", definition, None), ()
991995
if definition is None:
992996
return Resolved(data, "out_of_scope", None, None), ()
993997
_, carried = spelled(kind, name)

‎packages/zarr-metadata/tests/v3/test_definitions.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ def test_error_a_required_configuration_is_missing() -> None:
394394

395395

396396
def test_error_the_configuration_is_not_an_object() -> None:
397+
# Unread, and still claimed by the definition its name names.
397398
resolved, found = resolve({"name": "gzip", "configuration": 5}, CodecDefinition, SCOPE)
398-
assert resolved.resolution == "invalid"
399+
assert (resolved.resolution, resolved.definition) == ("invalid", GZIP_CODEC)
399400
assert [found.loc for found in found] == [("configuration",)]
400401

401402

‎packages/zarr-metadata/tests/v3/test_pipelines.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ def test_error_a_codec_out_of_order(codecs: list[JSONValue], index: int) -> None
206206
assert _problems(codecs) == [((index,), "invalid_value")]
207207

208208

209+
def test_error_a_codec_out_of_order_whose_configuration_is_not_an_object() -> None:
210+
# Its name still says what it is.
211+
assert _problems([{"name": "gzip", "configuration": 5}, "bytes"]) == [
212+
((0, "configuration"), "invalid_type"),
213+
((1,), "invalid_value"),
214+
]
215+
216+
209217
def test_error_a_second_array_to_bytes_codec() -> None:
210218
assert _problems(["bytes", "bytes"]) == [((1,), "invalid_value")]
211219

0 commit comments

Comments
 (0)