fix(serializer): don't leak relation_native_type into embedded documents - #8508
Merged
soyuka merged 1 commit intoSep 9, 2026
Conversation
Since 4.3.15 the relation_native_type context key set for a relation in createAndValidateAttributeValue() was never cleared when an embedded document was denormalized. It leaked through the embedded resource and any plain DTOs below it, so a nested IRI was validated by getResourceFromIri() against the outer relation's declared type and rejected with 400 "Invalid IRI" even though it resolved to exactly the declared class. Clear the key in denormalize() once the data is an embedded document: relations inside it set their own relation_native_type before resolving their IRIs, so the union and type-confusion guards keep working. Fixes api-platform#8507
Member
|
thanks for this! does this also fixes #8503 ? |
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.
Since 4.3.15 the
relation_native_typecontext key (set for a relation increateAndValidateAttributeValue(), read by the IRI type-confusion guard ingetResourceFromIri()) is never cleared when an embedded document is denormalized. It leaks through the embedded resource and any plain DTOs below it, so a nested IRI is validated against the outer relation's declared type and rejected with400 Invalid IRI, even though it resolves to exactly the declared class.Shape: resource
A→ embedded resource collectionB(writableLink: true) → plain DTO collectionC→ IRI to resourceD. Details and root-cause walkthrough in #8507.Fix: in
AbstractItemNormalizer::denormalize(), once the data is an embedded document (after the\is_string($data)IRI branch), drop the key so children start clean. Relations inside the embedded document still set their ownrelation_native_typebefore resolving their IRIs, so the union/type-confusion guards keep working (UnionIriCollectionTest,TypeConfusionRelationIriTestunchanged and green).Tests:
tests/Functional/Serializer/EmbeddedRelationNativeTypeTest.phpwith Doctrine-free fixtures undertests/Fixtures/TestBundle/ApiResource/EmbeddedRelationNativeType/(resource → embedded resource collection → plain DTO collection → IRI):Invalid IRI "/embedded_relation_targets/1".before the fix, 201 after;Also verified against a 2955-test downstream functional suite on 4.3.18.