Since version 5, with the new multiple-instances feature, there's a gap with the ScopedContainer "proxy" - namely it doesn't wrap the hasDefinition method.
This then creates a problem when you have Doctrine's type inference active (seemingly by default if either ORM or ODM is available) in the main instance, but want a new instance with no Doctrine metadata inference: the Extension class first removes the Doctrine-related definitions for the cloned instance, but later the DoctrinePass uses ScopedContainer::hasDefinition to check if it should decorate and modify that definition. Since hasDefinition isn't overriden, the check actually passes, since the "root" instance does have it - but then getDefinition wraps the ID for the specific instance, and no such definition exists.
Steps required to reproduce the problem
Add a new serializer instance with infer_types_from_doctrine_metadata set to false in a project with Doctrine ORM/ODM active:
Attempt to compile the application container (e.g. bin/console cache:clear) or run anything in debug, which should also force recompilation.
Expected Result
Cache cleared successfully, application container compiled successfully and/or whatever command was passed should at least reach its execution phase when in debug mode.
Actual Result
Failure compiling the application container:
$ bin/console cache:clear -vvv
// Clearing the cache for the dev environment with debug true
// Clearing outdated warmup directory...
// Warming up cache...
In ContainerBuilder.php line 992:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
You have requested a non-existent service "jms_serializer.instance.my_instance.metadata.doctrine_type_driver".
Exception trace:
at /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php:992
Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/ScopedContainer.php:72
JMS\SerializerBundle\DependencyInjection\ScopedContainer->getDefinition() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/Compiler/DoctrinePass.php:31
JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass->processInstance() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/Compiler/PerInstancePass.php:19
JMS\SerializerBundle\DependencyInjection\Compiler\PerInstancePass->process() at /var/www/html/vendor/symfony/dependency-injection/Compiler/Compiler.php:80
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php:767
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:506
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:763
Symfony\Component\HttpKernel\Kernel->preBoot() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:126
Symfony\Component\HttpKernel\Kernel->boot() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:144
Symfony\Component\HttpKernel\Kernel->reboot() at /var/www/html/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:229
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /var/www/html/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:141
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:326
Symfony\Component\Console\Command\Command->run() at /var/www/html/vendor/symfony/console/Application.php:1096
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:126
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:324
Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:175
Symfony\Component\Console\Application->run() at /var/www/html/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /var/www/html/vendor/autoload_runtime.php:29
require_once() at /var/www/html/bin/console:11
Since version 5, with the new multiple-instances feature, there's a gap with the ScopedContainer "proxy" - namely it doesn't wrap the
hasDefinition
method.This then creates a problem when you have Doctrine's type inference active (seemingly by default if either ORM or ODM is available) in the main instance, but want a new instance with no Doctrine metadata inference: the Extension class first removes the Doctrine-related definitions for the cloned instance, but later the DoctrinePass uses
ScopedContainer::hasDefinition
to check if it should decorate and modify that definition. SincehasDefinition
isn't overriden, the check actually passes, since the "root" instance does have it - but thengetDefinition
wraps the ID for the specific instance, and no such definition exists.Steps required to reproduce the problem
infer_types_from_doctrine_metadata
set tofalse
in a project with Doctrine ORM/ODM active:bin/console cache:clear
) or run anything in debug, which should also force recompilation.Expected Result
Actual Result
Failure compiling the application container:
In ContainerBuilder.php line 992:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]
You have requested a non-existent service "jms_serializer.instance.my_instance.metadata.doctrine_type_driver".
Exception trace: at /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php:992 Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/ScopedContainer.php:72 JMS\SerializerBundle\DependencyInjection\ScopedContainer->getDefinition() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/Compiler/DoctrinePass.php:31 JMS\SerializerBundle\DependencyInjection\Compiler\DoctrinePass->processInstance() at /var/www/html/vendor/jms/serializer-bundle/DependencyInjection/Compiler/PerInstancePass.php:19 JMS\SerializerBundle\DependencyInjection\Compiler\PerInstancePass->process() at /var/www/html/vendor/symfony/dependency-injection/Compiler/Compiler.php:80 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php:767 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:506 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:763 Symfony\Component\HttpKernel\Kernel->preBoot() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:126 Symfony\Component\HttpKernel\Kernel->boot() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:144 Symfony\Component\HttpKernel\Kernel->reboot() at /var/www/html/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:229 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /var/www/html/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:141 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /var/www/html/vendor/symfony/console/Command/Command.php:326 Symfony\Component\Console\Command\Command->run() at /var/www/html/vendor/symfony/console/Application.php:1096 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:126 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/html/vendor/symfony/console/Application.php:324 Symfony\Component\Console\Application->doRun() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:80 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:175 Symfony\Component\Console\Application->run() at /var/www/html/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /var/www/html/vendor/autoload_runtime.php:29 require_once() at /var/www/html/bin/console:11
cache:clear [--no-warmup] [--no-optional-warmers]