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

[FrameworkBundle] Fix setting default context for certain normalizers #57273

Merged

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented May 31, 2024

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.

Comment on lines 58 to 88
$kernel = static::createKernel(['test_case' => 'Serializer', 'root_config' => 'default_context.yaml']);
$container = $kernel->getContainerWithLoadedExtensions();

$services = array_merge(
$container->findTaggedServiceIds('serializer.normalizer'),
$container->findTaggedServiceIds('serializer.encoder')
);
foreach ($services as $serviceId => $attributes) {
$class = $container->getDefinition($serviceId)->getClass();
if (null === $reflectionConstructor = (new \ReflectionClass($class))->getConstructor()) {
continue;
}
foreach ($reflectionConstructor->getParameters() as $reflectionParam) {
if ('array $defaultContext' === $reflectionParam->getType().' $'.$reflectionParam->getName()) {
yield [$serviceId.'.alias'];
break;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made this dynamic in case new normalizers/encoders were added. Is it worth it, no idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this into a separate config were circular_reference_handler and max_depth_handler are not set.

@ruudk
Copy link
Contributor

ruudk commented Jun 3, 2024

@HypeMC I just tested it and it does indeed solve my problem. Thanks!

@fabpot Just a heads up. It would be great to have this fix also in 7.1.1.

Copy link
Contributor

@dbu dbu left a comment

Choose a reason for hiding this comment

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

i just ran into this regression with Symfony 6.4.

maybe the maintainers could merge just the BC break fix quickly and look into the expanded tests separately, to at least fix the problem? meanwhile i will need to lock onto version 6.4.7 to prevent the bug. 5.4.39 and ~7.0 would be versions without the bug - 7.1.0 has the bug so if you are on 7.1 you are out of luck.

but i also like the idea of adding the missing tests to prevent the regression from re-occurring.

@HypeMC HypeMC force-pushed the fix-setting-default-context-for-certain-normalizers branch 2 times, most recently from 484bf10 to 416c891 Compare June 11, 2024 02:01
@dbu
Copy link
Contributor

dbu commented Jun 12, 2024

the ci failures seem unrelated to the changes: fabbot seems to look at the DI extension class because it is touched, but the complaints are not about the changes in this PR, and appveyor fails on something completely unrelated.

if the latest 5.4 branch is green, this PR could be rebased on 5.4 to get them green.

@HypeMC HypeMC force-pushed the fix-setting-default-context-for-certain-normalizers branch from 416c891 to 653e8e0 Compare June 14, 2024 09:27
@HypeMC HypeMC force-pushed the fix-setting-default-context-for-certain-normalizers branch 3 times, most recently from d2735c0 to f903893 Compare June 14, 2024 10:01
@fabpot
Copy link
Member

fabpot commented Jun 15, 2024

Thank you @HypeMC.

@fabpot fabpot merged commit 5c2633f into symfony:5.4 Jun 15, 2024
18 of 22 checks passed
@ruudk
Copy link
Contributor

ruudk commented Jun 15, 2024

Thanks @HypeMC for all the work fixing this 🥳

@HypeMC HypeMC deleted the fix-setting-default-context-for-certain-normalizers branch June 15, 2024 20:29
@ruudk
Copy link
Contributor

ruudk commented Jun 27, 2024

@fabpot Could this be tagged for 7.1?

@fabpot
Copy link
Member

fabpot commented Jun 27, 2024

As it was merged in 5.4, it will indeed be part of the next 7.1 release.

utexas-wcms pushed a commit to utdk/pantheon_saml_integration that referenced this pull request Jul 1, 2024
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

6 participants