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] Catch \Throwable in getCacheKey() #36336

Closed
wants to merge 2 commits into from

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Apr 3, 2020

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #36332 (comment)
License MIT
Doc PR n/a

serialize() can throw \Throwable with PHP 7+, and it will if you try to serialize a Doctrine entity. As the serialization context will likely contain Doctrine entity, this must be caught.

'ignored' => $this->ignoredAttributes,
'camelized' => $this->camelizedAttributes,
]));
} catch (\Throwable $exception) {
Copy link
Member

Choose a reason for hiding this comment

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

\Exception?
catching \Throwable is a terrible practice, it hides coding issues and helps ppl lose their time to figure out what is broken...

Copy link
Member Author

@dunglas dunglas Apr 3, 2020

Choose a reason for hiding this comment

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

Not here, it's a very specific edge case, see #36332 (comment)
(We were already catch \Exception)

Copy link
Member Author

@dunglas dunglas Apr 3, 2020

Choose a reason for hiding this comment

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

If we don't do that, if any value in the context contains a Doctrine entity, an error can be thrown, leading to a 500.

@dunglas dunglas force-pushed the serializer-catch-throwable branch 2 times, most recently from 1b8e7f0 to 86ab77c Compare April 3, 2020 14:05
@dunglas dunglas force-pushed the serializer-catch-throwable branch from 86ab77c to f4cd9a5 Compare April 3, 2020 14:06
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 3, 2020

I opened https://bugs.php.net/79447
To me, this should be fixed at the PHP level instead.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Apr 3, 2020
@nicolas-grekas
Copy link
Member

I've submitted php/php-src#5396 to fix the issue on the PHP side, please have a look.

@nicolas-grekas
Copy link
Member

PR on php-src accepted, this is going to be fixed on PHP's side. Anyone having this issue, please upgrade to PHP >= 7.4.6.

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

4 participants