The Wayback Machine - https://web.archive.org/web/20221107000810/https://github.com/symfony/symfony/pull/47128
Skip to content
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

[Serializer] Throw InvalidArgumentException if the data needed in the constructor doesn't belong to a backedEnum #47128

Merged
merged 1 commit into from Aug 19, 2022

Conversation

alli83
Copy link

@alli83 alli83 commented Jul 30, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #46977 [Serializer] Collect deserialization errors on enum cause TypeError
License MIT
Doc PR

Targeted case: Deserialization with "collect_denormalization_errors" set but the data to be serialized does not correspond to the scalar value of the targeted enum instance in the object's constructor.
updated in last commit : Keep "from "(in the previous commits I had switched to "tryFrom") to map the data submitted to an enum instance targeted.

Imho, even if the "collect_denormalization_errors" is specified, this type of error seems to have to be caught upstream. By just trying to collect the error we do not prevent the object from being instantiated. But this action is bound to fail because we already know that the data is not valid (checked by the BackedEnumNormalizer). This instantiation 'failure' leads to a confusing/misleading error (i.e. Argument # 1 ($test) must be of type TestEnum, string given) which is not the original error.

@carsonbot
Copy link

carsonbot commented Jul 30, 2022

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Copy link
Member

@chalasr chalasr left a comment

Thanks for the PR! I'm not totally sure about the current patch though

@chalasr
Copy link
Member

chalasr commented Jul 31, 2022

/cc @alexandre-daubois as you are the author of that normalizer

@alli83 alli83 force-pushed the issue_46977 branch 2 times, most recently from 62f439b to 3451834 Compare Aug 17, 2022
@alli83 alli83 changed the title [Serializer] Return null and handle as InvalidArgumentException instead of ValueError if the data doesn't belong to a backed enum [Serializer] Throw InvalidArgumentException if the data needed in the constructor doesn't belong to a backedEnum Aug 18, 2022
Copy link
Member

@chalasr chalasr left a comment

This looks good to me as it seems to fix the buggy case at hand as proven by the added tests.

fabpot
fabpot approved these changes Aug 19, 2022
@fabpot
Copy link
Member

fabpot commented Aug 19, 2022

Thank you @alli83.

@fabpot fabpot merged commit cb3684e into symfony:5.4 Aug 19, 2022
9 of 11 checks passed
@alli83 alli83 deleted the issue_46977 branch Aug 19, 2022
This was referenced Aug 26, 2022
@fabpot fabpot mentioned this pull request Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants