-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
ObjectNormalizer is not provided with serializer default_context #57316
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
Comments
@HypeMC , thanks for the fast reply Yes, #57273 fixes my issue, it's actually really close to what I suggested above as a possible solution Do you have any idea when this fix will be provided for I assume that currently I will have to add some workaround to make it work until this fix is released |
No, but bug fix versions are released approximately every month, so once the PR is merged, it shouldn't take long.
You can stick to 6.4.7 until then, if I'm not mistaking, the bug is not present in that version. |
Thanks for a suggestion |
…normalizers (HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Fix setting default context for certain normalizers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #56875, fix #57316 | License | MIT Caused by #54791. The main problem is that `$context` defaults to `[]` instead of `$defaultContext`. There's a test to check this, but it didn't work when `circular_reference_handler` or `max_depth_handler` were not `null`. I also found an issue with `serializer.normalizer.property`. Since it’s not tagged with `serializer.normalizer`, which, to my understanding, is intentional, it would never have the default context bound to it. Commits ------- f903893 [FrameworkBundle] Fix setting default context for certain normalizers
Symfony version(s) affected
6.4.8
Description
When
default_context
is set in framework.yaml globally - Symfony\Component\Serializer\Normalizer\ObjectNormalizer is missing them in specific circumstances. I have declared this inframework.yaml
Symfony\Component\Serializer\DependencyInjection\SerializerPass.php
does the bindingsymfony/src/Symfony/Component/Serializer/DependencyInjection/SerializerPass.php
Line 55 in cf4ef92
But after
bin/console c:c
ObjectNormalizer has an empty array passed to $defaultContextnew \Symfony\Component\Serializer\Normalizer\ObjectNormalizer($c, $d, $b, $e, new \Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata($c), NULL, [], $e)
That's what is passed after cache clearing in
App_KernelDevDebugContainer.php
.If I manually enable autowiring in
services.yaml
like this:binding works and defaultContext is passed there. But looks like generally the issue is that bindings conflict with arguments setting somewhere during building process. Because, for example, ProblemNormalizer has $defaultContext passed correctly and it is not autowired by default as well.
My expectation is to have defaultContext passed there by default if it is configured globally for ObjectNormalizer
How to reproduce
symfony new 64lts --version="6.4.8"
composer require symfony/serializer
,composer require symfony/property-access
dev
environment andAPP_DEBUG=true
framework.yaml
bin/console c:c
Check ObjectNormalizer declaration in container. $defaultContext is empty.
Possible Solution
I see several options to solve this.
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Line 2004 in cf4ef92
Looks like on this line we already have $defaultContext variable containing empty array or globally set default_context if configured. And it is a bit weird that $defaultContext variable will be considered only if
circular_reference_handler
ormax_depth_handler
exist.And in case if these two options are missing - empty $context variable is set to ObjectNormalizer 6th argument. if we set $defaultContext here instead of declaring empty $context - it will work.
Additional Context
No response
The text was updated successfully, but these errors were encountered: