fix(state): convert BackedEnum denormalization errors into validation violations#8195
Merged
soyuka merged 1 commit intoMay 22, 2026
Conversation
… 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
d25cb28 to
60db9f9
Compare
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.
Summary
When a backed enum property receives an invalid value, the deserializer throws
NotNormalizableValueException, producing a400response. Validation constraints (Assert\Choice, validation groups) are never executed, breaking consistency for APIs that rely on a single 422 +ConstraintViolationListflow.This patch makes
DeserializeProvidercatch the exception when its expected types (directly or via the previous chain) point to aBackedEnum, convert it to aConstraintViolationwithType::INVALID_TYPE_ERROR, and rethrow asValidationException. The user now gets a 422 with apropertyPath.Other denormalization errors keep their current 400 behavior, preserving BC (the
testNullOnNonNullablePropertyReturns400test still passes).Closes #8183
Test plan
EnumDenormalizationValidationTestcovers default operation andcollectDenormalizationErrors: trueoperationValidationTest::testPostWithDenormalizationErrorsCollectedstill greenNullOnNonNullablePropertyTest::testNullOnNonNullablePropertyReturns400still green