fix(doctrine): guard unmapped relation links in ORM handleLinks#8293
Open
soyuka wants to merge 2 commits into
Open
fix(doctrine): guard unmapped relation links in ORM handleLinks#8293soyuka wants to merge 2 commits into
soyuka wants to merge 2 commits into
Conversation
A GraphQL item query crashed with a Doctrine MappingException when the resource had a public property typed as the resource class but not mapped as a Doctrine association (e.g. a transient self reference). LinkFactory builds a relation Link from the property's native type, and the GraphQL root-item link filter keeps self references (toClass === resourceClass). The ORM LinksHandlerTrait then called getAssociationMapping() unguarded, throwing "No mapping found for field ... on class ...". Skip the link when the property is not an actual association, matching the existing hasAssociation() guard in the ODM trait. The identifier-self link still applies WHERE id=X. Closes api-platform#8292
The new hasAssociation() guard in handleLinks queries the mocked ClassMetadata, which returned false by default and skipped the join the test expected. Stub it to true for the mapped 'company' association.
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.
A GraphQL item query crashed with a Doctrine
MappingExceptionwhen the queried resource had a public property typed as the resource class but not mapped as a Doctrine association (e.g. a transient/runtime-only self reference).LinkFactory::createLinksFromRelations()builds a relationLinkfor any property whose native type resolves to a resource class — without checking it is an actual association. The GraphQL root-item link filter inDoctrine\Common\State\LinksHandlerTrait::getLinks()keeps self references (toClass === resourceClass).Doctrine\Orm\State\LinksHandlerTrait::handleLinks()then calledgetAssociationMapping()unguarded and threw:Regression introduced in #8237 (GraphQL item query dispatched through its own provider, 4.3).
This guards the association lookup with
hasAssociation()— matching the guard already present in the ODMLinksHandlerTrait. When the property is not a mapped association the link is skipped; the identifier-self link still appliesWHERE id = X.Added a functional GraphQL test (ORM): two persisted items, queries the second, asserts no
errorsand the correct item is returned (proving the identifier filter still applies after the unmapped link is skipped).