-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Fix denormalizing custom class in UidNormalizer #44600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-grekas
merged 1 commit into
symfony:5.3
from
fancyweb:serializer/fix-custom-uid
Dec 15, 2021
Merged
[Serializer] Fix denormalizing custom class in UidNormalizer #44600
nicolas-grekas
merged 1 commit into
symfony:5.3
from
fancyweb:serializer/fix-custom-uid
Dec 15, 2021
Conversation
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
0634cf2
to
ba9e002
Compare
fancyweb
commented
Dec 13, 2021
} catch (\InvalidArgumentException $exception) { | ||
throw new NotNormalizableValueException(sprintf('The data is not a valid "%s" string representation.', $type)); | ||
} catch (\Error $e) { | ||
if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching the error and looking for the message looks better than doing reflection to me, maybe there's a better way?
nicolas-grekas
approved these changes
Dec 15, 2021
Thank you @fancyweb. |
nicolas-grekas
added a commit
that referenced
this pull request
Dec 15, 2021
This PR was merged into the 5.3 branch. Discussion ---------- [Serializer] Fix symfony/uid requirement | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | no | New feature? | no | Deprecations? | - | Tickets | - | License | MIT | Doc PR | - #44600 needs 8247779 Commits ------- 6a0fd54 [Serializer] Fix symfony/uid requirement
This was referenced Dec 29, 2021
Merged
Merged
Merged
nicolas-grekas
added a commit
that referenced
this pull request
Feb 23, 2022
…alization in UidNormalizer (fancyweb) This PR was merged into the 6.1 branch. Discussion ---------- [Serializer] Deprecate support for abstract uid denormalization in UidNormalizer | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT | Doc PR | - Continuation of #44600. All abstract classes should not be denormalized to Uuid::class. We need a concrete class. Instead of penalizing everyone with reflection in supportsDenormalization(), let's just bubble up the PHP \Error (we are going to do the same in UidValueResolver). Commits ------- 6fc4287 [Serializer] Deprecate support for abstract uid denormalization in UidNormalizer
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.
Considering we support denormalizing any subclass of
AbstractUid::class
we should not denormalize any$type !== Ulid::class
toUuid::class
because this is wrong. We need to call$type::fromString
(seeTestCustomUid
).But
fromString()
is an abstract method, so it cannot be called directly on abstract classes, I guess we should have not supported them from the start. However, since they work right now (since all abstract classes fall back to theUuid:class
behavior) we cannot break it. So I propose to deprecate supporting abstract classes in 6.1 and remove it in 7.0.