fix(serializer): forward DiscriminatorMap defaultType in PropertyMetadataLoader#8346
Merged
soyuka merged 1 commit intoJun 23, 2026
Merged
Conversation
…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
c5f0085 to
7da2e07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PropertyMetadataLoaderrebuilds Symfony'sClassDiscriminatorMappingfrom the#[DiscriminatorMap]attribute but only forwardstypePropertyandmapping— it silently drops the 3rd constructor argumentdefaultType(added in Symfony Serializer 7.1).The bug only surfaces with a warmed serializer mapping cache (
cache:warmupin prod). In dev/test the metadata is built lazily through Symfony'sAttributeLoader, which forwardsdefaultType, so it stays invisible there. With the default lost,AbstractItemNormalizer::getClassDiscriminatorResolvedClass()seesdefaultType === nulland throws:This forwards the third argument, guarded so it stays compatible with
symfony/serializer ^6.4where the attribute exposes nodefaultType.Test
testForwardsDiscriminatorDefaultTypeis skipped onsymfony/serializer < 7.1(whereClassDiscriminatorMapping::getDefaultType()does not exist).