-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Description
Symfony version(s) affected
6.4.*
Description
If your app has symfony/framework-bundle installed in version 6.4 and also symfony/serializer in version 7.4.0 (because your dependencies allow it), then the following error will occur, if both framework.annotations and framework.serializer.enable_attributes are enabled:
TypeError {#7183
#message: "Symfony\Component\Serializer\Mapping\Loader\AttributeLoader::__construct(): Argument #1 ($allowAnyClass) must be of type ?bool, Doctrine\Common\Annotations\PsrCachedReader given, called in var\cache\prod\ContainerRCIQnfY\getSerializer_Mapping_CacheWarmerService.php on line 25"
#code: 0
#file: "vendor\symfony\serializer\Mapping\Loader\AttributeLoader.php"
#line: 50
trace: {
vendor\symfony\serializer\Mapping\Loader\AttributeLoader.php:50 { …}
var\cache\prod\ContainerRCIQnfY\getSerializer_Mapping_CacheWarmerService.php:25 {
ContainerRCIQnfY\getSerializer_Mapping_CacheWarmerService::do($container, $lazyLoad = true)^
›
› return $container->privates['serializer.mapping.cache_warmer'] = new \Symfony\Bundle\FrameworkBundle\CacheWarmer\SerializerCacheWarmer([new \Symfony\Component\Serializer\Mapping\Loader\AttributeLoader(($container->privates['annotations.cached_reader'] ?? $container->load('getAnnotations_CachedReaderService')))],
($container->targetDir.''.'/serialization.php'));
› }
}
var\cache\prod\ContainerRCIQnfY\Contao_ManagerBundle_HttpKernel_ContaoKernelProdContainer.php:860 { …}
var\cache\prod\ContainerRCIQnfY\getCacheWarmerService.php:29 { …}
vendor\symfony\http-kernel\CacheWarmer\CacheWarmerAggregate.php:99 { …}
vendor\symfony\http-kernel\Kernel.php:554 { …}
vendor\contao\manager-bundle\src\HttpKernel\ContaoKernel.php:291 { …}
vendor\symfony\http-kernel\Kernel.php:772 { …}
ctest5\vendor\symfony\http-kernel\Kernel.php#L126vendor\symfony\http-kernel\Kernel.php:126 { …}
vendor\symfony\framework-bundle\Console\Application.php:190 { …}
vendor\symfony\framework-bundle\Console\Application.php:72 { …}
vendor\symfony\console\Application.php:195 { …}
vendor\contao\manager-bundle\bin\contao-setup:49 { …}
vendor\bin\contao-setup:119 { …}
}
}
How to reproduce
You can check out a minimum example here: https://github.com/fritzmg/symfony-serializer-issue
It is also reproducible with this composer.json:
{
"type": "project",
"require": {
"contao/manager-bundle": "5.6.*",
"symfony/framework-bundle": "^6.4"
},
"extra": {
"contao-component-dir": "assets"
},
"scripts": {
"post-install-cmd": [
"@php vendor/bin/contao-setup"
],
"post-update-cmd": [
"@php vendor/bin/contao-setup"
]
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": false,
"contao/manager-plugin": true
}
}
}Simply create this composer.json and run composer update.
Another more "real world" example would be:
{
"type": "project",
"require": {
"contao/manager-bundle": "5.6.*",
"madeyourday/contao-rocksolid-frontend-helper": "2.2.10"
},
"extra": {
"contao-component-dir": "assets"
},
"scripts": {
"post-install-cmd": [
"@php vendor/bin/contao-setup"
],
"post-update-cmd": [
"@php vendor/bin/contao-setup"
]
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"php-http/discovery": false,
"contao/manager-plugin": true
}
}
}Possible Solution
I am not quite certain how this can be solved. The fact that symfony/framework-bundle from Symfony 6 might be incompatible with other Symfony packages from Symfony 7 is not surprising, but I am not sure how packages should define their dependencies, if their code allows ^6.4 || ^7.4 for both symfony/framework-bundle and symfony/serializer, but then another third party package only allows ^6.4 for symfony/framework-bundle, but has no requirement for symfony/serializer.
In fact, even the dev dependencies of symfony/framework-bundle specifically allow symfony/serializer 7.4.0:
| "symfony/serializer": "^6.4|^7.0", |
And its conflicts only disallow symfony/serializer lower than 6.4:
| "symfony/serializer": "<6.4", |