symfony: [DI] ServiceContainer build error after upgrading to 4.1.4

Symfony version(s) affected: 4.1.4

Description

After upgrading to v4.1.4 the following error shown when container tries to build.

RuntimeException Cannot dump definitions which have method calls.

Tace RuntimeException Cannot dump definitions which have method calls. [Symfony\Component\DependencyInjection\Exception\RuntimeException] Cannot dump definitions which have method calls.

Exception trace: Symfony\Component\DependencyInjection\Dumper\PhpDumper->dumpValue() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:614 Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServiceMethodCalls() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:516 Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServiceInlinedDefinitions() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:792 Symfony\Component\DependencyInjection\Dumper\PhpDumper->addService() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:827 Symfony\Component\DependencyInjection\Dumper\PhpDumper->addServices() at /var/www/html/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:194 Symfony\Component\DependencyInjection\Dumper\PhpDumper->dump() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:704 Symfony\Component\HttpKernel\Kernel->dumpContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:541 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /var/www/html/vendor/symfony/http-kernel/Kernel.php:123 Symfony\Component\HttpKernel\Kernel->boot() at /var/www/html/vendor/symfony/framework-bundle/Console/Application.php:65 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/vendor/symfony/console/Application.php:145 Symfony\Component\Console\Application->run() at /var/www/html/bin/console:39

possibly BC break possibly caused by: #28060 (or maybe i missed something and used it wrong)

How to reproduce
I have a monolog handler that requires EntityManagerInterface and a doctrine EventSubscriber that needs the monolog logger with the handler. It works fine when I downgrade to symfony/dependency-injection to v4.1.3

Files that requre to reproduce:

src/Monolog/DoctrineDBHandler.php

namespace App\Monolog;

use Doctrine\ORM\EntityManagerInterface;
use Monolog\Handler\AbstractProcessingHandler;

class DoctrineDBHandler extends AbstractProcessingHandler
{
    private $entityManager;

    public function __construct(EntityManagerInterface $em)
    {
        parent::__construct();
        $this->entityManager = $em;
    }

    protected function write(array $record): void
    {
        // write log to db
    }
}
src/EventSubscriber/DoctrineLogSubscriber.php

namespace App\EventSubscriber;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Monolog\Logger;

class DoctrineLogSubscriber implements EventSubscriber
{
    private $logger;

    public function __construct(Logger $logger)
    {
        $this->logger = $logger;
    }

    public function getSubscribedEvents(): array
    {
        return ['postPersist'];
    }

    public function postPersist(LifecycleEventArgs $args): void
    {
        $this->logger->addInfo('create');
    }
}
config/services.yaml

parameters:
    locale: 'en'

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    App\:
        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    App\DoctrineLogSubscriber:
        arguments: ['@monolog.logger.demo']
        tags:
            - { name: doctrine.event_subscriber }

config/packages/dev/monolog.yaml

...
monolog:
    channels: ['demo']
    handlers:
        main:
            type: stream
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            channels: ["!event"]
        console:
            type: console
            process_psr_3_messages: false
            channels: ["!event", "!doctrine", "!console"]
        demo:
            channels: ['demo']
            level: INFO
            type: service
            id: App\Monolog\DoctrineDBHandler

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 23 (11 by maintainers)

Commits related to this issue

Most upvoted comments

We have this problem in 3.4.15, I’ll check if I can work out a small reproduction too.

I can confirm that requiring symfony/proxy-manager-bridge fixes the issue.

Thanks to the reproducer, I managed to reduce the reproducer to a config like:


services:
    foo:
        class: c
        public: true
        arguments:
            - '@bar'
            - !service
                class: c
                properties:
                    p: !service
                        class: c
                        properties:
                            p: !service
                                class: c

    bar:
        class: c
        public: true
        properties:
            p: !service
                class: c
                arguments: ['@foo']

Indirectly related to proxy-manager indeed. On it now…

It looks like composer require symfony/proxy-manager-bridge fixes the issue.

It fixes my original problem. I’m just not sure, that adding a new dependency is the right way to fix a bug introduced in a patch release.

This is solved but not tagged.

Can confirm, that a simple composer require symfony/dependency-injection:4.1.3 solves the problem for the moment.