Skip to content

fix(zarr-metadata): compare the declarations a configuration holds whatever order it writes them in - #451

Closed
d-v-b wants to merge 2 commits into
mainfrom
fix/zarr-metadata-nested-declaration-order
Closed

d-v-b wants to merge 2 commits into
mainfrom
fix/zarr-metadata-nested-declaration-order

Conversation

@d-v-b

@d-v-b d-v-b commented Nov 16, 2026

Copy link
Copy Markdown
Owner

🤖 AI text below 🤖

Two declarations that hold other declarations, such as two sharding_indexed codecs, are now equal when they differ only in the order their configurations write their members in. The declarations a configuration holds were compared in the order it writes them, so a shard that writes index_codecs before codecs was not equal to one that writes them the other way round, and neither were the array models that hold them, although the order of the members of a JSON object means nothing. The items of an array, such as the codecs of a pipeline, are still compared in order.

How it was found, and the change

The agent found this while testing canonical documents: a v3 array document and the same document with the members of every object reversed read as two unequal models when it held a shard. Attributes, extra fields, unclaimed configurations and a configuration's own members are compared as sorted JSON text, so their order never mattered. Only _nested_key in definition/_definition.py kept written order, because it iterated the nested mapping. It now sorts by location, with a sort key that never compares an object key with an array index.

refines already compared nested declarations by location, so it is unchanged. hash follows ==, since both use the key.

Tests and checks
  • tests/v3/test_definitions.py: three cases added to the table of test_two_declarations_are_equal_when_they_read_the_same. A shard with its members reversed is equal (this case fails without the fix), a shard with its index codecs in another order is not, and a codec with no nested declarations and its members reversed is equal, as before.
  • Run locally: the package suite, ruff 0.17.3 and pyright.
Stack bookkeeping

🤖 Generated with Claude Code

…atever order it writes them in

`declaration_key` paired each nested declaration's key with its location,
in the order the configuration wrote them. So two `sharding_indexed`
codecs that differed only in whether `codecs` or `index_codecs` came
first had different keys, and were not equal, although the order of the
members of a JSON object means nothing and the rest of a configuration
is already compared as sorted JSON text. The array models that held them
were not equal either.

The nested keys are now sorted by location. An index of an array sorts
by its number, so the items of an array, such as the codecs of a
pipeline, are still compared in order.

Assisted-by: ClaudeCode:claude-fable-5-2
@d-v-b

d-v-b commented Nov 16, 2026

Copy link
Copy Markdown
Owner Author

🤖 AI text below 🤖

Closed by the agent in favour of zarr-developers#4641, which is the same branch opened upstream.

@d-v-b d-v-b closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant