Skip to content

fix: tighten array metadata field validation - #4704

Open
barlowa124 wants to merge 5 commits into
zarr-developers:mainfrom
barlowa124:meta-validate-4453
Open

barlowa124 wants to merge 5 commits into
zarr-developers:mainfrom
barlowa124:meta-validate-4453

Conversation

@barlowa124

Copy link
Copy Markdown
Contributor

Supersedes #4494, which GitHub auto-closed when the branch history was rewritten to remove tooling attribution.

Summary

Refs #4453, fifth checklist item. Four array metadata fields accepted
JSON outside the spec contract.

shape: [true] parsed as (1,) because bool subclasses int.
Document shape fields now reject booleans through
parse_shapelike(..., reject_bool=True) while stored
chunks/chunk_shape keep the lenient default: old versions wrote
true there and repair tests codify reading them. attributes: []
parsed as {}. parse_attributes now requires a dict with string
keys, matching GroupMetadata's existing check.
dimension_names: "xy" parsed as ("x", "y") since a bare string is
iterable. Strings and bytes are excluded before the element check.
storage_transformers: {"name": ...} parsed as a tuple of keys.
mappings are excluded from the iterable check.

Non-Mapping attributes now emit a ZarrDeprecationWarning rather
than raising, since older documents wrote list-valued attributes.
That moved from rejection to deprecation during review. Bool
dimension_names elements are deprecated the same way.

For reviewers

parse_shapelike gains a keyword-only reject_bool flag whose
lenient default preserves the repair path for stored chunk sizes.
attributes: null still parses to {}, matching the group's handling
of missing attributes.

Author attestation

  • I am a human. These are my changes. I have reviewed and understood every change and can explain why each is correct.

TODO

Done:

  • Add unit tests and/or doctests in docstrings

Outstanding:

  • 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)

Four metadata fields accepted out-of-contract JSON:

- shape accepted booleans ([true] read as (1,)); document shape fields
  now reject them via parse_shapelike(reject_bool=True). Stored
  chunks/chunk_shape fields keep the lenient default since older
  versions wrote true there and repair tests codify reading them.
- attributes accepted a list; it now requires a dict with string keys,
  matching the check GroupMetadata already applies.
- dimension_names accepted a bare string, iterating it into
  characters; strings and bytes are excluded before the element check.
- storage_transformers accepted a dict, iterating it into keys;
  mappings are excluded.

Refs zarr-developers#4453
- parse_attributes checks Mapping rather than dict and emits
  ZarrDeprecationWarning for out-of-contract input instead of raising;
  dict(data) still runs so accepted values behave exactly as before
- parse_shapelike loses the reject_bool kwarg; bools now warn
  (ZarrDeprecationWarning) wherever they parse, ahead of rejection once
  the deprecation window elapses
- dimension_names string/bytes exclusion and storage_transformers
  mapping exclusion unchanged
- tests updated: bools and non-mapping attributes are covered by
  pytest.warns cases; repair fixtures reading stored true chunks keep
  their assertions

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant