schmittjoh / JMSSerializerBundle

Easily serialize, and deserialize data of any complexity (supports XML, JSON, YAML)
http://jmsyst.com/bundles/JMSSerializerBundle
MIT License
1.8k stars 311 forks source link

Failure to compile application container when using additional instances with Doctrine type inference disabled per-instance #945

Closed CRC-Mismatch closed 7 months ago

CRC-Mismatch commented 7 months ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

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

  1. Add a new serializer instance with infer_types_from_doctrine_metadata set to false in a project with Doctrine ORM/ODM active:
    # config/packages/jms_serializer.yaml
    jms_serializer:
    # ...
    instances:
        my_instance:
            inherit: true
            metadata:
                infer_types_from_doctrine_metadata: false
    #...
  2. Attempt to compile the application container (e.g. bin/console cache:clear) or run anything in debug, which should also force recompilation.

Expected Result

Actual Result

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]