Skip to content

fix(state): convert BackedEnum denormalization errors into validation violations#8195

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/enum-denormalization-validation-8183
May 22, 2026
Merged

fix(state): convert BackedEnum denormalization errors into validation violations#8195
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/enum-denormalization-validation-8183

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 21, 2026

Summary

When a backed enum property receives an invalid value, the deserializer throws NotNormalizableValueException, producing a 400 response. Validation constraints (Assert\Choice, validation groups) are never executed, breaking consistency for APIs that rely on a single 422 + ConstraintViolationList flow.

This patch makes DeserializeProvider catch the exception when its expected types (directly or via the previous chain) point to a BackedEnum, convert it to a ConstraintViolation with Type::INVALID_TYPE_ERROR, and rethrow as ValidationException. The user now gets a 422 with a propertyPath.

Other denormalization errors keep their current 400 behavior, preserving BC (the testNullOnNonNullablePropertyReturns400 test still passes).

Closes #8183

Test plan

  • New functional test EnumDenormalizationValidationTest covers default operation and collectDenormalizationErrors: true operation
  • Existing ValidationTest::testPostWithDenormalizationErrorsCollected still green
  • Existing NullOnNonNullablePropertyTest::testNullOnNonNullablePropertyReturns400 still green
  • Full Symfony functional sweep (885 tests, 0 regression)

… violations

When a backed enum property received an invalid value, the deserializer
threw NotNormalizableValueException producing a 400 response. Validation
constraints (Assert\Choice, validation groups) were never executed.

Catch the exception in DeserializeProvider when its expected types
(directly or via the previous chain) point to a BackedEnum, convert to
a ConstraintViolation and rethrow as ValidationException so the response
is a 422 with a propertyPath. Other denormalization errors keep their
current 400 behavior, preserving BC.

Closes api-platform#8183
@soyuka soyuka force-pushed the fix/enum-denormalization-validation-8183 branch from d25cb28 to 60db9f9 Compare May 22, 2026 11:26
@soyuka soyuka merged commit 44bb18d into api-platform:4.3 May 22, 2026
120 checks passed
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