Skip to content

Keep keys without a normalizer in array shapes - #241

Merged
DavidBadura merged 1 commit into
2.1.xfrom
array-shape-keep-unmapped-keys
Nov 6, 2026
Merged

DavidBadura merged 1 commit into
2.1.xfrom
array-shape-keep-unmapped-keys

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

ArrayShapeNormalizer only kept the keys that had an inner normalizer, and because of isset() it also dropped keys holding null. For array{height: int, addresses: list<Address>} the height was lost on extract and on hydrate. Now the normalizer converts the keys that have a normalizer and keeps everything else as it is.

What a caller can notice: inner normalizers now get null for a key that holds null, like normalizers of top level properties and of ArrayNormalizer items already do, so a normalizer that is not null safe will throw there now. Keys without a normalizer, also ones that are not part of the shape, are kept raw on both sides, and the output follows the order of the input array. Data that was written before the fix is still missing the dropped keys.

Found while moving patchlevel/odm to hydrator 2 (patchlevel/odm#29).

ArrayShapeNormalizer only returned the keys it had an inner normalizer for,
so every other key of the shape was silently dropped on extract and hydrate.
Keys holding null were dropped too because of isset(). The normalizer now
works on the given array and only converts the keys it has a normalizer for,
null included, and keeps everything else as it is, like ArrayNormalizer and
plain arrays do.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Hello 👋

Here are the most recent benchmark results, compared against 2.1.x. Time is the mode over the iterations in the its column, with the relative standard deviation in brackets.

StackHydrator

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb -21.21% 1.103μs (±0.54%) 1.116μs (±0.94%) +1.19%
benchExtract1Object 1000 5 1.856mb -21.21% 1.309μs (±0.66%) 1.325μs (±2.31%) +1.20%
benchHydrate1000Objects 3 5 1.856mb -21.21% 1.075ms (±1.47%) 1.087ms (±1.42%) +1.06%
benchExtract1000Objects 3 5 1.856mb 0.00% 1.113ms (±0.78%) 1.100ms (±0.63%) -1.09%

StackHydratorWithCryptography

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 1.702μs (±0.49%) 1.705μs (±0.56%) +0.15%
benchExtract1Object 1000 5 1.856mb 0.00% 4.092μs (±1.89%) 4.107μs (±0.90%) +0.36%
benchHydrate1000Objects 3 5 1.856mb 0.00% 1.664ms (±1.08%) 1.680ms (±2.07%) +0.94%
benchExtract1000Objects 3 5 1.856mb 0.00% 3.885ms (±1.53%) 3.832ms (±0.64%) -1.35%

StackHydratorWithLazy

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 0.174μs (±3.73%) 0.175μs (±2.13%) +0.29%
benchHydrate1ObjectTriggerInit 1000 5 1.856mb 0.00% 1.496μs (±1.08%) 1.476μs (±1.06%) -1.36%
benchHydrate1000Objects 3 5 1.856mb 0.00% 165.378μs (±0.86%) 168.244μs (±1.99%) +1.73%
benchHydrate1000ObjectsTriggerInit 3 5 1.856mb 0.00% 1.467ms (±0.68%) 1.469ms (±0.66%) +0.10%

This comment gets updated every time a new commit comes in.

@DavidBadura DavidBadura added the bug Something isn't working label Nov 6, 2026
@DavidBadura DavidBadura added this to the 2.1.1 milestone Nov 6, 2026
@DavidBadura
DavidBadura merged commit 0fa034f into 2.1.x Nov 6, 2026
17 checks passed
@DavidBadura
DavidBadura deleted the array-shape-keep-unmapped-keys branch November 6, 2026 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants