Skip to content

fix(serializer): clarify nested-document error with actionable hints#8238

Closed
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/nested-document-adder-remover-hint-8077
Closed

fix(serializer): clarify nested-document error with actionable hints#8238
soyuka wants to merge 1 commit into
api-platform:4.3from
soyuka:fix/nested-document-adder-remover-hint-8077

Conversation

@soyuka

@soyuka soyuka commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

The denormalizer error "Nested documents for attribute X are not allowed. Use IRIs instead." only mentioned one of two possible remedies. When a developer intends nested embedding, switching to IRIs is the wrong fix — the right one is to add matching denormalization groups (and, for to-many relations, adder/remover methods on the parent class).

Updated the exception message to surface both options so the failure is self-diagnosing.

Reproduction

POST a parent resource with a nested OneToMany collection without @ids and without addX/removeX accessors on the parent. The old message wrongly nudged users toward IRIs.

Test plan

  • Updated testInnerDocumentNotAllowed in AbstractItemNormalizerTest to assert the new message.
  • Updated testNestedRelationDocumentReturns400Problem in tests/Functional/Hal/ProblemTest.
  • PHPStan + php-cs-fixer clean on changed files.

Fixes #8077

The previous "Use IRIs instead." hint only told users one of two
possible remedies. When a developer intends nested embedding, the real
fix is to add matching denormalization groups on the related resource
(and, for to-many relations, adder/remover methods on the parent),
not to switch to IRIs. Expand the message to surface both options so
the failure mode is self-diagnosing.

Fixes api-platform#8077
@soyuka

soyuka commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

Closing per maintainer feedback: the existing error message is sufficient and users can look up the remedy online. Closing the underlying issue with usage guidance instead.

@soyuka soyuka closed this Jun 4, 2026
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