Skip to content

Infer normalizers for nullable collection items - #242

Closed
DavidBadura wants to merge 4 commits into
2.1.xfrom
normalizer-inference-fixes
Closed

DavidBadura wants to merge 4 commits into
2.1.xfrom
normalizer-inference-fixes

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

The collection branch of inferNormalizerByType() unwrapped the nullable type of the collection instead of its items, so list<?Skill>, array<string, ?Status>, list<?DateTimeImmutable> and every other collection with nullable items got no normalizer and were stored raw. The second fix stops ArrayShapeNormalizer::handleType() from reading type info for an explicit map key that the docblock shape does not have, which raised warnings. The third commit is a pure simplification: the collection and shape branches no longer unwrap item types and look for a class normalizer themselves, since the recursive call does both, and that duplicate is where the first bug came from.

Release note: collections with nullable items of objects, enums or dates are now normalized. Before, the raw objects went into the payload, and hydrating returned arrays or strings instead of the declared type. Enums keep the same JSON. Old payloads with dates ({"date": ..., "timezone_type": ..., "timezone": ...}) or value objects can no longer be hydrated after the update, so stored events with such collections need an upcaster that converts them to the normalized format. Custom normalizers used for such items now also receive null.

Please merge #241 first. This change gives shapes reached through nullable items an ArrayShapeNormalizer, and without #241 that normalizer drops the keys it has no normalizer for.

The collection branch unwrapped the nullable item type from the collection
itself instead of from the item type, so collections like list<?Skill> got no
normalizer at all and their items were passed through as raw objects.
An explicit ArrayShapeNormalizer map can contain keys that the property's
docblock shape doesn't know. handleType read those keys anyway and raised
undefined key warnings. Such fields are now left alone, like the whole map is
when the property type isn't an array shape.
The collection and array shape branches unwrapped nullable item types and
looked for a class normalizer before recursing, although inferNormalizerByType
does both on its own. Dropping the duplicate removes the place where the
nullable item bug came from.
The shape branch of inferNormalizerByType was only reached through the
hydrator tests, which do not cover the metadata factory.
@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.510μs (±1.35%) 2.477μs (±3.68%) -1.30%
benchExtract1Object 1000 5 1.856mb -21.21% 2.818μs (±1.00%) 2.751μs (±1.26%) -2.36%
benchHydrate1000Objects 3 5 1.856mb 0.00% 2.422ms (±1.34%) 2.437ms (±1.23%) +0.63%
benchExtract1000Objects 3 5 1.856mb 0.00% 2.269ms (±1.04%) 2.283ms (±0.73%) +0.62%

StackHydratorWithCryptography

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 3.688μs (±0.89%) 3.658μs (±1.59%) -0.80%
benchExtract1Object 1000 5 1.856mb 0.00% 8.148μs (±0.62%) 8.241μs (±0.65%) +1.14%
benchHydrate1000Objects 3 5 1.856mb 0.00% 3.656ms (±0.78%) 3.622ms (±0.65%) -0.94%
benchExtract1000Objects 3 5 1.856mb 0.00% 7.592ms (±1.14%) 7.563ms (±0.62%) -0.38%

StackHydratorWithLazy

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 0.424μs (±4.21%) 0.411μs (±1.81%) -3.06%
benchHydrate1ObjectTriggerInit 1000 5 1.856mb 0.00% 3.010μs (±1.07%) 2.970μs (±0.42%) -1.35%
benchHydrate1000Objects 3 5 1.856mb 0.00% 397.840μs (±1.07%) 403.477μs (±2.91%) +1.42%
benchHydrate1000ObjectsTriggerInit 3 5 1.856mb 0.00% 2.964ms (±5.01%) 2.979ms (±0.99%) +0.50%

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

Covered by #244 (1.24.4), which reaches 2.1.x with the merge-up in #246.

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