Skip to content

fix(symfony): keep error serialization mapping when enable_attributes is disabled#8231

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/enable-attributes-false-error-8174
Jun 3, 2026
Merged

fix(symfony): keep error serialization mapping when enable_attributes is disabled#8231
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/enable-attributes-false-error-8174

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 3, 2026

Summary

When framework.serializer.enable_attributes: false, Symfony's attribute loader is configured with no mapped classes and returns early for every class, so api-platform's Error and ValidationException lose the #[Groups]/#[SerializedName]/#[Ignore] metadata that the error normalizers rely on, leaving error responses empty.

Reproduction

Set framework.serializer.enable_attributes: false on the demo project and trigger a validation error — the response body is empty instead of the structured error payload.

Test plan

  • Added failing test covering the bug.
  • Test passes after the fix.
  • Related test classes still pass locally.

Fixes #8174

… is disabled

When `framework.serializer.enable_attributes: false`, Symfony registers its built-in
attribute loader with `allowAnyClass: false` and no mapped classes, so it returns
early for every class. As a result, api-platform's `Error` and `ValidationException`
lose their `#[Groups]`, `#[SerializedName]`, and `#[Ignore]` metadata, and the
problem/hydra/json:api error normalizers emit an empty payload.

Register a dedicated `AttributeLoader` in `serializer.mapping.chain_loader` (and the
cache warmer) that hard-codes the api-platform error classes via the `mappedClasses`
argument. The loader runs regardless of the global `enable_attributes` flag, so error
responses keep their structure without re-enabling attribute discovery for user
classes.

Fixes api-platform#8174
@soyuka soyuka merged commit 277589d into api-platform:4.3 Jun 3, 2026
107 of 108 checks passed
@soyuka soyuka deleted the fix/enable-attributes-false-error-8174 branch June 3, 2026 14:45
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