Skip to content

[FrameworkBundle] Fix passing serializer.default_context option to normalizers #47637

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
Sep 29, 2022

Conversation

wuchen90
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
License MIT

The default_context config option under serializer of FrameworkBundle isn't taken into account when using Symfony\Component\Serializer\Normalizer\ObjectNormalizer.
Maybe it's the case for other serializers but let's fix one at a time.

@wuchen90
Copy link
Contributor Author

Related to #47012

@nicolas-grekas nicolas-grekas changed the title [Serializer] Fix ObjectNormalizer that doesn't use default_context config option [FrameworkBundle] Fix passing serializer.default_context option to normalizers Sep 28, 2022
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

(I fixed the other normalizers that had the same issue)

/cc @soyuka @dunglas

@@ -6,9 +6,16 @@ framework:
enabled: true
default_context:
enable_max_depth: true
# The option below is used in \Symfony\Bundle\FrameworkBundle\Tests\Functional\SerializerTest::testObjectNormalizerUsesDefaultContextConfigOption
# to assert that the `default_context` is taken into account in serializers
Copy link
Member

Choose a reason for hiding this comment

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

The test itself should be enough to spot any issue quickly so I'm not sure this is useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right.
Maybe do I need to change the test to take into account the other normalizers that have the same behavior with $defaultContext since @nicolas-grekas has fixed them too?

Copy link
Member

@nicolas-grekas nicolas-grekas Sep 29, 2022

Choose a reason for hiding this comment

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

that'd be nice if you can yes !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
I changed the tests to target all normalizers and encoders that are tagged serializer.normalizer or serializer.encoder and that have the argument $defautContext in their constructor, the same as what SerializerPass does.

@wuchen90 wuchen90 changed the title [FrameworkBundle] Fix passing serializer.default_context option to normalizers [FrameworkBundle] Fix passing serializer.default_context option to normalizers and encoders Sep 29, 2022
@wuchen90 wuchen90 changed the title [FrameworkBundle] Fix passing serializer.default_context option to normalizers and encoders [FrameworkBundle] Fix passing serializer.default_context option to normalizers Sep 29, 2022
@nicolas-grekas
Copy link
Member

Thank you @wuchen90.

@nicolas-grekas nicolas-grekas merged commit a5f8bb2 into symfony:5.4 Sep 29, 2022
@wuchen90 wuchen90 deleted the fix-serializer branch September 29, 2022 10:07
This was referenced Sep 30, 2022
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.

5 participants