Skip to content

Pass non-array values from ObjectNormalizer to the hydrator - #239

Merged
DavidBadura merged 1 commit into
2.1.xfrom
object-normalizer-class-normalizer
Nov 7, 2026
Merged

DavidBadura merged 1 commit into
2.1.xfrom
object-normalizer-class-normalizer

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

ObjectNormalizer::normalize() goes through extract(), which applies the class normalizer of the object, so the result can be a scalar. denormalize() rejected everything that was not an array before calling hydrate(), so a property with an explicit #[ObjectNormalizer] whose class has its own normalizer could be written but never read back.

Now non-array values are passed on to the hydrator, which uses the class normalizer or throws ArrayDataRequired if there is none. Through the hydrator the thrown exception stays a DenormalizationFailure, only the previous exception changes from InvalidArgument to ArrayDataRequired.

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

@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% 2.458μs (±1.79%) 2.426μs (±0.87%) -1.28%
benchExtract1Object 1000 5 1.856mb -21.21% 2.781μs (±1.13%) 2.715μs (±0.64%) -2.37%
benchHydrate1000Objects 3 5 1.856mb 0.00% 2.431ms (±0.46%) 2.438ms (±1.18%) +0.29%
benchExtract1000Objects 3 5 1.856mb 0.00% 2.287ms (±1.15%) 2.269ms (±2.59%) -0.76%

StackHydratorWithCryptography

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 3.684μs (±0.93%) 3.648μs (±1.83%) -0.98%
benchExtract1Object 1000 5 1.856mb 0.00% 8.437μs (±1.15%) 8.215μs (±0.96%) -2.63%
benchHydrate1000Objects 3 5 1.856mb 0.00% 3.634ms (±2.26%) 3.594ms (±0.68%) -1.12%
benchExtract1000Objects 3 5 1.856mb 0.00% 7.776ms (±0.83%) 7.594ms (±0.87%) -2.35%

StackHydratorWithLazy

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 0.412μs (±2.65%) 0.407μs (±0.82%) -1.11%
benchHydrate1ObjectTriggerInit 1000 5 1.856mb 0.00% 2.971μs (±0.45%) 2.957μs (±0.86%) -0.45%
benchHydrate1000Objects 3 5 1.856mb 0.00% 412.328μs (±4.37%) 403.618μs (±0.93%) -2.11%
benchHydrate1000ObjectsTriggerInit 3 5 1.856mb 0.00% 2.947ms (±1.15%) 2.936ms (±0.70%) -0.38%

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

@DavidBadura DavidBadura added this to the 2.1.1 milestone Nov 6, 2026
@DavidBadura DavidBadura added the bug Something isn't working label Nov 6, 2026
@DavidBadura

Copy link
Copy Markdown
Member Author

Rebased on top of the 2.0.x merge-up in #246, so please merge that one first. Until then the diff here also shows the commits from #246.

Extracting an object applies its class normalizer, so the result can be a
scalar, but denormalize rejected everything that was not an array. Such a
property could be written but never read back. Now the hydrator decides: it
uses the class normalizer or throws ArrayDataRequired if there is none.
@DavidBadura
DavidBadura force-pushed the object-normalizer-class-normalizer branch from 722399b to 68fb733 Compare November 7, 2026 10:50
@DavidBadura
DavidBadura merged commit 092dae4 into 2.1.x Nov 7, 2026
17 checks passed
@DavidBadura
DavidBadura deleted the object-normalizer-class-normalizer branch November 7, 2026 10:58
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