Skip to content

fix(serializer): forward DiscriminatorMap defaultType in PropertyMetadataLoader#8346

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/8345-discriminator-defaulttype
Jun 23, 2026
Merged

fix(serializer): forward DiscriminatorMap defaultType in PropertyMetadataLoader#8346
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/8345-discriminator-defaulttype

Conversation

@soyuka

@soyuka soyuka commented Jun 23, 2026

Copy link
Copy Markdown
Member
Q A
Branch? 4.3
Tickets Fixes #8345
License MIT
Doc n/a

PropertyMetadataLoader rebuilds Symfony's ClassDiscriminatorMapping from the #[DiscriminatorMap] attribute but only forwards typeProperty and mapping — it silently drops the 3rd constructor argument defaultType (added in Symfony Serializer 7.1).

The bug only surfaces with a warmed serializer mapping cache (cache:warmup in prod). In dev/test the metadata is built lazily through Symfony's AttributeLoader, which forwards defaultType, so it stays invisible there. With the default lost, AbstractItemNormalizer::getClassDiscriminatorResolvedClass() sees defaultType === null and throws:

Type property "discr" not found for the abstract object "App\Entity\MyAbstractResource".

This forwards the third argument, guarded so it stays compatible with symfony/serializer ^6.4 where the attribute exposes no defaultType.

Test testForwardsDiscriminatorDefaultType is skipped on symfony/serializer < 7.1 (where ClassDiscriminatorMapping::getDefaultType() does not exist).

…dataLoader

PropertyMetadataLoader rebuilt Symfony's ClassDiscriminatorMapping from the
#[DiscriminatorMap] attribute but only forwarded typeProperty and mapping,
silently dropping the third constructor argument defaultType (Symfony 7.1+).

The bug only surfaces with a warmed serializer mapping cache (cache:warmup in
prod). In dev/test the metadata is built lazily through Symfony's AttributeLoader,
which forwards defaultType, so it stays invisible. With the default lost,
AbstractItemNormalizer::getClassDiscriminatorResolvedClass() sees a null
defaultType and throws "Type property ... not found for the abstract object".

Forward the third argument, guarded so it stays compatible with
symfony/serializer ^6.4 where the attribute exposes no defaultType.

Fixes api-platform#8345
@soyuka soyuka force-pushed the fix/8345-discriminator-defaulttype branch from c5f0085 to 7da2e07 Compare June 23, 2026 12:30
@soyuka soyuka merged commit be26bbe into api-platform:4.3 Jun 23, 2026
107 of 112 checks passed
@soyuka soyuka deleted the fix/8345-discriminator-defaulttype branch June 23, 2026 13:48
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