Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Add FlattenException Normalizer #37087

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
merged 1 commit into from
Aug 23, 2020

Conversation

monteiro
Copy link
Contributor

@monteiro monteiro commented Jun 3, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #32719 ...
License MIT
Doc PR No docs ...

I have just duplicated the PR #33650 (from @skalpa) but using the new component ErrorHandler and removing the priority.

Project that reproduces the bug on Symfony 5.2: https://github.com/monteiro/serializer-pr37087 (all steps are on the README).

Since this adds a new class and changes behavior, we add this new feature on the 5.2 branch.

@monteiro monteiro requested a review from dunglas as a code owner June 3, 2020 16:03
@monteiro monteiro changed the title Add FlattenException Normalizer [Fix] Add FlattenException Normalizer Jun 3, 2020
@monteiro
Copy link
Contributor Author

monteiro commented Jun 3, 2020

I still need to test well the priority, because it works on my symfony 5.0 (without it), but I want to try it on Symfony 4.4 to see if I have the same behavior.

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API platform normalizes FlattenException at a very low prio, is it an issue?

@nicolas-grekas nicolas-grekas changed the title [Fix] Add FlattenException Normalizer [Serializer] Add FlattenException Normalizer Jun 4, 2020
@monteiro monteiro requested a review from nicolas-grekas June 4, 2020 10:48
@nicolas-grekas nicolas-grekas added this to the 4.4 milestone Jun 4, 2020
@monteiro monteiro requested a review from nicolas-grekas June 4, 2020 13:04
@monteiro
Copy link
Contributor Author

monteiro commented Jun 4, 2020

I have 2 unit tests failing:

There were 2 errors:
1) Symfony\Component\Serializer\Tests\Normalizer\FlattenExceptionNormalizerTest::testNormalize with data set "instance from constructor" (Symfony\Component\ErrorHandler\Exception\FlattenException Object (...))
TypeError: Return value of Symfony\Component\ErrorHandler\Exception\FlattenException::getMessage() must be of the type string, null returned
/home/travis/build/symfony/symfony/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php:190
/home/travis/build/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/FlattenExceptionNormalizer.php:37
/home/travis/build/symfony/symfony/src/Symfony/Component/Serializer/Tests/Normalizer/FlattenExceptionNormalizerTest.php:46
2) Symfony\Component\Serializer\Tests\Normalizer\FlattenExceptionNormalizerTest::testDenormalizeValidData
TypeError: Return value of Symfony\Component\ErrorHandler\Exception\FlattenException::getMessage() must be of the type string, null returned
/home/travis/build/symfony/symfony/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php:190
/home/travis/build/symfony/symfony/src/Symfony/Component/Serializer/Tests/Normalizer/FlattenExceptionNormalizerTest.php:93

@nicolas-grekas Maybe you can help me with this. I know that on the FlattenException Unit tests you never use the constructor without arguments.

You did the change in the past adding typehints to the FlattenException class methods, which makes total sense when you are creating this exception from throwable. But what can we do in this specific case?

Should I still use the empty constructor here or should I use reflection?

If I use it, makes sense to test the empty constructor but since they have different type hints from the getters (Example: message is null in the empty constructor, but getMessage() has a string typehint) the test fails.

Or should I follow the FlattenException unit tests and remove the empty constructor test?

Note: This does not happen in this specific feature, because the normalizer does not call any getter without a full FlattenException.

@monteiro monteiro force-pushed the flatten-exception-denormalizer branch from 459b375 to a5aae27 Compare August 9, 2020 14:42
@monteiro monteiro force-pushed the flatten-exception-denormalizer branch from a5aae27 to 6c1b966 Compare August 9, 2020 15:00
@monteiro monteiro force-pushed the flatten-exception-denormalizer branch from 6c1b966 to 0981943 Compare August 20, 2020 07:38
Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the reasoning. That works for me.

@monteiro monteiro force-pushed the flatten-exception-denormalizer branch from c39cb1b to c528a31 Compare August 21, 2020 13:44
@monteiro monteiro changed the base branch from 4.4 to master August 21, 2020 13:44
@monteiro monteiro requested a review from fabpot August 21, 2020 14:26
@monteiro monteiro changed the title [Serializer] Add FlattenException Normalizer [Messenger] Add FlattenException Normalizer Aug 21, 2020
@fabpot
Copy link
Member

fabpot commented Aug 21, 2020

Tests need to be updated to pass.

@monteiro
Copy link
Contributor Author

@fabpot I have updated the tests but some Travis tests are failing with the error that the FlattenExceptionNormalizer class does not exist (FrameworkBundle is fetching v5.0 in Travis).

I suppose that will only be green when we merge this or am I missing something?

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are broken because of the constraints in composer.json. I will fix it while merging.

@fabpot fabpot force-pushed the flatten-exception-denormalizer branch from c91b71a to 78fbd0a Compare August 23, 2020 08:56
@fabpot
Copy link
Member

fabpot commented Aug 23, 2020

Thank you @monteiro.

@fabpot fabpot merged commit 12f8631 into symfony:master Aug 23, 2020
@xabbuh xabbuh modified the milestones: 4.4, next Aug 27, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
@monteiro monteiro deleted the flatten-exception-denormalizer branch December 5, 2020 09:21
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.

[Messenger] Message retried in failure transport dropped on exception
7 participants