Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
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 toba9e002Compare| }catch (\InvalidArgumentException$exception) { | ||
| thrownewNotNormalizableValueException(sprintf('The data is not a valid "%s" string representation.',$type)); | ||
| }catch (\Error$e) { | ||
| if (str_starts_with($e->getMessage(),'Cannot instantiate abstract class')) { |
ContributorAuthor
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 changesDec 15, 2021
Member
nicolas-grekas commentedDec 15, 2021
Thank you@fancyweb. |
nicolas-grekas added a commit that referenced this pull requestDec 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 needs8247779Commits-------6a0fd54 [Serializer] Fix symfony/uid requirement
This was referencedDec 29, 2021
Merged
Merged
Merged
nicolas-grekas added a commit that referenced this pull requestFeb 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 freeto 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::classwe should not denormalize any$type !== Ulid::classtoUuid::classbecause 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:classbehavior) we cannot break it. So I propose to deprecate supporting abstract classes in 6.1 and remove it in 7.0.