-
-
Notifications
You must be signed in to change notification settings - Fork 893
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
BC introduced in 3.1.15 when denormalizing a variable in a type than already been denormalized previously #6024
Comments
looks weird, does the exception occurs when you denormalize by hand? You should use a context in your call, maybe that you:
|
Hi Soyuka, What do you mean by "denormalizing by hand" ? Is it not what I'm already doing in DummyProcessor?
Instead of :
The denormamization of Foo is just completely skipped. My hypothesis is that happens because of getFactoryOptions() returning wrong cached $options. I can see that $operationCacheKey values change between 3.1.14 and 3.1.15. |
I see, do you have any idea on how we could fix this? |
I understand now why it breaks: In v3.1.14, the $context was built in AbstractItemNormalizer::createOperationContext() and, if the class you were denormalizing was an ApiResource, unset($context['operation'], $context['operation_name']);
$context['resource_class'] = $resourceClass;
if ($this->resourceMetadataCollectionFactory) {
try {
$context['operation'] = $this->resourceMetadataCollectionFactory->create($resourceClass)->getOperation();
$context['operation_name'] = $context['operation']->getName();
} catch (OperationNotFoundException) {
}
} From v3.1.15 onwards, the $context is built in src/Serializer/OperationContextTrait.php and the This is a problem because the $operationCacheKey = ($context['resource_class'] ?? '').($context['operation_name'] ?? '').($context['api_normalize'] ?? ''); So, in v3.1.15 onwards and for a given class, the $operationCacheKey is always the same in all denormalization calls whereas it had different values before v3.1.15 depending on To fix it, we should either continue to set |
Thanks for digging into this! |
API Platform version(s) affected: ^3.1.15
Description
Hi,
It took me ages to find the problem on this one but a part of our app is broken as soon as we upgrade to ^3.1.15. The BC has been indroduced with this PR : #5663 and is linked to the modifications in src/Serializer/AbstractItemNormalizer.php.
The problem happens in a very specific case: if you try to denormalize manually an item of a type that has been already previously denormalized, the denormalization doesn't hydrate correctly the object.
How to reproduce
With :
If you do a POST on /dummies with the following body:
In v3.1.14, you correctly received a 201 response with the following body:
In v3.1.15, the denormalization in DummyProcessor does not hydrate correctly the Foo object and you get an Exception : "Typed property App\ApiResource\Foo::$bar must not be accessed before initialization"
Possible Solution
No real idea so far
Additional Context
I haven't been able to find the exact problem but this is linked to the $operationCacheKey used in AbstractItemNormalizer::getFactoryOptions
The text was updated successfully, but these errors were encountered: