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 unitialized properties (from PHP 7.4.2) when serializing context for the cache key#36332
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dunglas commentedApr 3, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
To be honest, I'm not sure if what you describe in the description is a bug or not, because when using typed properties, you must always initialize the property, either in its definition of in the constructor, that's the spirit of this feature. However, your patch is legit, because according to the Doctrine documentation:
Could you add a test to prevent regressions? (Just testing than putting something to serializable such as a closure in |
dunglas commentedApr 3, 2020
Also, there is probably something to fix in Doctrine too. Our call to |
alanpoulain commentedApr 3, 2020
It cannot really tested since serializing a closure will throw an exception, not an error (and the exception is catched). |
2ec0b4 commentedApr 3, 2020
Pay attention to the destination branch: symfony:3.4 here, but the initial issue#35574 is about symfony:4.4. This should be applied on several versions? I reproduce this behavior on SF 4.4 here:doctrine/common#886 (comment) |
dunglas commentedApr 3, 2020
@alanpoulain for the test you can do the like it that:https://github.com/symfony/symfony/pull/36336/files#diff-e6bd6c603753788029968840196a888cR395 @2ec0b4 patches are merged to upper branches, it will be fixed in 3.4 and all superior versions. |
…zing context for the cache key
03bd90a to1fafff7Comparefabpot commentedApr 4, 2020
Thank you@alanpoulain. |
Uh oh!
There was an error while loading.Please reload this page.
This bug only happens on the following conditions:
Book) having a relation with another entity (Author) is used;Authorentity uses typed properties (PHP 7.4) not initialized;Serializeris used with theBookin theOBJECT_TO_POPULATEkey in the context.For instance:
Or even:
If the following is done (it's the case for instance in API Platform when a
PUTis made):Then there will be the following error:
It's because of these lines in the
getCacheKeymethod of theAbstractObjectNormalizer:symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Lines 405 to 409 in5da141b
Since the lazy proxyfied relation has a
__sleepwith unitialized properties, theserializemethod will throw (sincehttps://bugs.php.net/bug.php?id=79002:php/php-src@846b647).I propose to fix this issue by unsetting the
OBJECT_TO_POPULATEkey in the context because I don't think it's useful for determining the attributes of the object.For the next versions of Symfony, the fix should probably be elsewhere, in the default context.
For instance in Symfony 4.4, instead of:
symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Line 118 in15edfd3
It should be:
But I'm not sure how it should be merged (another PR maybe?).