Skip to content

[DI] ServiceContainer build error after upgrading to 4.1.4 #28296

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

Closed
mmarton opened this issue Aug 28, 2018 · 23 comments
Closed

[DI] ServiceContainer build error after upgrading to 4.1.4 #28296

mmarton opened this issue Aug 28, 2018 · 23 comments

Comments

@mmarton
Copy link

mmarton commented Aug 28, 2018

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
@mmarton mmarton changed the title ServiceContainer build error after upgrading to 4.1.4 [DI] ServiceContainer build error after upgrading to 4.1.4 Aug 28, 2018
@nicolas-grekas
Copy link
Member

Hello, thanks for the report.
Can you please create a small app app we could clone to reproduce the issue? That would help a lot. Thanks.

@mmarton
Copy link
Author

mmarton commented Aug 28, 2018

Hello.
It's here: https://github.com/mmarton/symfony-di-error-poc

@codedmonkey
Copy link
Contributor

codedmonkey commented Aug 28, 2018

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

@dmaicher
Copy link
Contributor

@nicolas-grekas seems its indeed caused by #28060

for some service definitions with method-calls this condition + continue here now prevents them from being added to $this->definitionVariables:

https://github.com/symfony/symfony/pull/28060/files#diff-f7b23d463cba27ac5e4cb677f2be7623R509

So they are not dumped here:

https://github.com/nicolas-grekas/symfony/blob/e843bb86c88c9a52a6c9d3a98afb11f796624abe/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L1767

Which leads to the Exception. Unfortunately I don't fully understand all that logic so I cannot fix it 😄 🙈

@Webonaute
Copy link

Also have some issue. if services have calls method but are public: false, it throw exception.

@franzwilding
Copy link
Contributor

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

vitek-rostislav added a commit to shopsys/shopsys that referenced this issue Aug 30, 2018
vitek-rostislav added a commit to shopsys/shopsys that referenced this issue Aug 30, 2018
vitek-rostislav added a commit to shopsys/shopsys that referenced this issue Aug 30, 2018
vitek-rostislav added a commit to shopsys/shopsys that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/framework that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/product-feed-zbozi that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/product-feed-google that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/product-feed-heureka that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/product-feed-heureka-delivery that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/http-smoke-testing that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/form-types-bundle that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/migrations that referenced this issue Aug 30, 2018
MattCzerner pushed a commit to shopsys/project-base that referenced this issue Aug 30, 2018
@nicolas-grekas
Copy link
Member

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

@ghost
Copy link

ghost commented Sep 3, 2018

@nicolas-grekas

composer require symfony/proxy-manager-bridge
composer show | grep symfony/ | egrep "dependency|proxy"
	symfony/dependency-injection             v4.1.4     Symfony DependencyInjection Component
	symfony/proxy-manager-bridge             v4.1.4     Symfony ProxyManager Bridge

composer update
	Loading composer repositories with package information
	Updating dependencies (including require-dev)
	Package operations: 0 installs, 1 update, 0 removals
	Generating autoload files
	ocramius/package-versions:  Generating version class...
	ocramius/package-versions: ...done generating version class

	Executing script cache:clear [KO]
	 [KO]
	Script cache:clear returned with error code 1
	!!
	!!  In PhpDumper.php line 1543:
	!!
	!!    Cannot dump definitions which have method calls.
	!!
	!!
	!!
	Script @auto-scripts was called via post-update-cmd

@mmarton
Copy link
Author

mmarton commented Sep 3, 2018

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.

@ghost
Copy link

ghost commented Sep 3, 2018

@mmarton

You no longer see the "Cannot dump ..." error?

Did you in-fact also remove the DI 4.1.3 instance, allowing update back to 4.1.4?

@mmarton
Copy link
Author

mmarton commented Sep 3, 2018

@hal869

yes, it fixes my demo repository here: https://github.com/mmarton/symfony-di-error-poc

$ bin/console cache:clear
// Clearing the cache for the dev environment with debug true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.

$ composer show | grep symfony/ | egrep "dependency|proxy"
symfony/dependency-injection v4.1.4 Symfony DependencyInjection Component
symfony/proxy-manager-bridge v4.1.4 Symfony ProxyManager Bridge

@ghost
Copy link

ghost commented Sep 3, 2018

@mmarton

yes, it fixes my demo repository

well, then, hm :-/ still 'here', clearly. poking around for 'why' ...

p.s.
and

I'm just not sure, that adding a new dependency is the right way to fix a bug introduced in a patch release.

generally agree

@fmata
Copy link
Contributor

fmata commented Sep 3, 2018

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

@ghost
Copy link

ghost commented Sep 3, 2018

@nicolas-grekas

https://github.com/hal869/symfony-28296.git

composer show | egrep "dependency-injection|proxy-manager-bridge"
	symfony/dependency-injection             v4.1.4             Symfony DependencyInjectio...
	symfony/proxy-manager-bridge             v4.1.4             Symfony ProxyManager Bridge

composer update
	...
	Executing script cache:clear [KO]
	 [KO]
	Script cache:clear returned with error code 1
	!!
	!!  In PhpDumper.php line 1543:
	!!
	!!    Cannot dump definitions which have method calls.
	!!
	!!
	!!
	Script @auto-scripts was called via post-update-cmd

and

composer require symfony/dependency-injection:4.1.3
composer show | egrep "dependency-injection|proxy-manager-bridge"
	symfony/dependency-injection             v4.1.3             Symfony DependencyInjectio...
	symfony/proxy-manager-bridge             v4.1.4             Symfony ProxyManager Bridge
composer update
	...
	(no error)

@frostieDE
Copy link

frostieDE commented Sep 3, 2018

I cannot confirm that composer require symfony/proxy-manager-bridge fixes the problem:

PS D:\Dev\Web\idp> composer require symfony/proxy-manager-bridge
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing symfony/proxy-manager-bridge (v4.1.4): Downloading (100%)
Writing lock file
Generating autoload files
Endroid Installer detected project type "symfony"
- Configuring endroid/qr-code-bundle
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 1
!!
!!  In PhpDumper.php line 1543:
!!
!!    Cannot dump definitions which have method calls.
!!
!!
!!

PHP config:

PHP 7.2.8 (cli) (built: Jul 21 2018 03:45:17) ( NTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

@nicolas-grekas
Copy link
Member

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...

@nicolas-grekas
Copy link
Member

Can you please report if applying #28366 fixes your issue?

@ghost
Copy link

ghost commented Sep 4, 2018

@nicolas-grekas

cd /dev/web/test/
rm -rf *
git clone https://github.com/hal869/symfony-28296.git

cd symfony-28296
composer install
	...
	Executing script cache:clear [KO]
	 [KO]
	Script cache:clear returned with error code 1
	!!
	!!  In PhpDumper.php line 1543:
	!!
	!!    Cannot dump definitions which have method calls.
	!!
	!!
	!!
	Script @auto-scripts was called via post-install-cmd

composer show | egrep "dependency"
	symfony/dependency-injection             v4.1.4             Symfony DependencyInjectio...

git remote add nicolas-grekas-di-fix https://github.com/nicolas-grekas/symfony.git
git fetch nicolas-grekas-di-fix
git cherry-pick eca5db996d750267e0d0d123439fa4c6f7471bcc
git add -A
git commit -m "28296-di-fix"
git log | head
	commit 8c9eb20e77e444dd790be49c3e4afe3bc9a682b9
	Author: Nicolas Grekas <nicolas.grekas@gmail.com>
	Date:   Tue Sep 4 09:23:21 2018 +0200

	    28296-di-fix

composer update
	Executing script cache:clear [KO]
	 [KO]
	Script cache:clear returned with error code 1
	!!
	!!  In FileLoader.php line 168:
	!!
	!!    The autoloader expected class "App\Symfony\Component\DependencyInjection\Du
	!!    mper\PhpDumper" to be defined in file "/dev/web/test/symfony-28296/ven
	!!    dor/composer/../../src/Symfony/Component/DependencyInjection/Dumper/PhpDump
	!!    er.php". The file was found but the class was not in it, the class name or
	!!    namespace probably has a typo in /dev/web/test/symfony-28296/config/se
	!!    rvices.yaml (which is loaded in resource "/dev/web/test/symfony-28296/
	!!    config/services.yaml").
	!!
	!!
	!!  In DebugClassLoader.php line 288:
	!!
	!!    The autoloader expected class "App\Symfony\Component\DependencyInjection\Du
	!!    mper\PhpDumper" to be defined in file "/dev/web/test/symfony-28296/ven
	!!    dor/composer/../../src/Symfony/Component/DependencyInjection/Dumper/PhpDump
	!!    er.php". The file was found but the class was not in it, the class name or
	!!    namespace probably has a typo.
	!!
	!!
	!!
	Script @auto-scripts was called via post-update-cmd

@nicolas-grekas
Copy link
Member

@hal869 this must be related to some issue when applying the patch.

@fabpot fabpot closed this as completed Sep 5, 2018
nicolas-grekas added a commit that referenced this issue Sep 5, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix dumping some complex service graphs

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28296 (and its duplicates #28355 & #28362 ~+ possibly #28304~)
| License       | MIT
| Doc PR        | -

Commits
-------

769fd4b [DI] Fix dumping some complex service graphs
@alexislefebvre
Copy link
Contributor

alexislefebvre commented Sep 16, 2018

requiring symfony/proxy-manager-bridge

didn't worked for me, I blacklisted the 4.1.4 version of symfony/dependency-injection and it worked:

"symfony/dependency-injection": "^4.1 <4.1.4"

See liip/LiipFunctionalTestBundle#448 for an example.

@matheusdallrosa
Copy link

Also have some issue. if services have calls method but are public: false, it throw exception.

I'm using Symfony 3.4 and this do not solved my problem. I have no service with this properties, but i keep getting the error:

  In PhpDumper.php line 1761:                                                
                                                                             
    Cannot dump definitions which have method calls. 

I'll keep on 3.4.14.

@nicolas-grekas
Copy link
Member

This is solved but not tagged.

@mnavarrocarter
Copy link

I have this very same problem. I donwgraded to the symfony/dependency-injection 4.1.3 but to no avail. Building the container just consumed my 15gb or RAM. The guilty service is a Doctrine Event Subscriber. When I comment it out of my service definitions, then everything works fine.

ShopsysBot pushed a commit to shopsys/product-feed-heureka-delivery that referenced this issue Sep 22, 2023
ShopsysBot pushed a commit to shopsys/form-types-bundle that referenced this issue Sep 22, 2023
ShopsysBot pushed a commit to shopsys/migrations that referenced this issue Sep 22, 2023
ShopsysBot pushed a commit to shopsys/product-feed-zbozi that referenced this issue Sep 22, 2023
ShopsysBot pushed a commit to shopsys/product-feed-heureka that referenced this issue Sep 22, 2023
ShopsysBot pushed a commit to shopsys/product-feed-google that referenced this issue Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests