Skip to content

Adding lazy-loading listeners after construction is not supported. #29637

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
liverbool opened this issue Dec 18, 2018 · 23 comments
Closed

Adding lazy-loading listeners after construction is not supported. #29637

liverbool opened this issue Dec 18, 2018 · 23 comments

Comments

@liverbool
Copy link
Contributor

liverbool commented Dec 18, 2018

After upgrade from 4.1 to 4.2 i ran into this error when cache clear process.

In \Symfony\Bridge\Doctrine\ContainerAwareEventManager.php line 103:

  Adding lazy-loading listeners after construction is not supported.

I have no idea to fix it, Have someone can spot me for fixing?

Thanks!

@chalasr
Copy link
Member

chalasr commented Dec 18, 2018

Can you please add the full stack trace to your description? (including the caller)

@liverbool
Copy link
Contributor Author

liverbool commented Dec 18, 2018

I have nothing special just upgrade 4.1 to 4.2 (from old project) and got an error on cache:clear process.

@chalasr
Copy link
Member

chalasr commented Dec 18, 2018

Can you run the command with the -vvv option? You'll get a full stack trace

@xabbuh
Copy link
Member

xabbuh commented Dec 18, 2018

Well, without being able to see what is going on in your application we will still not be able to help you. The full stack trace or a small example application that allows to reproduce would help here.

@liverbool
Copy link
Contributor Author

liverbool commented Dec 18, 2018

@xabbuh I'll try to short out small pie of code to produce this error but hard to see which state i should start.

Here is -vvv output.

sf cach:c -vvv

[WARNING] Some commands could not be registered:

In ContainerAwareEventManager.php line 103:

[RuntimeException]
Adding lazy-loading listeners after construction is not supported.

Exception trace:
() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:103
Symfony\Bridge\Doctrine\ContainerAwareEventManager->addEventListener() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1116
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Dbal_DefaultConnectionService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1132
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2037
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getSylius_Repository_LocaleService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1992
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getSylius_LocaleProviderService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2459
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getChang_Locale_Router_LocaleProviderService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1778
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getRouterService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2189
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getTwigService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getTranslation_ExtractorService.php:18
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getIncenteevTranslationChecker_ExtractorService.php:12
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getConsole_Command_PublicAlias_IncenteevTranslationChecker_Command_FindMissingService.php:12
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:243
Symfony\Component\DependencyInjection\Container->make() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:225
Symfony\Component\DependencyInjection\Container->get() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:186
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:69
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /Users/dos/GitHub/phpmob/takeoff/bin/console:33

[WARNING] Some commands could not be registered:

In ContainerAwareEventManager.php line 103:

[RuntimeException]
Adding lazy-loading listeners after construction is not supported.

Exception trace:
() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:103
Symfony\Bridge\Doctrine\ContainerAwareEventManager->addEventListener() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1116
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Dbal_DefaultConnectionService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1132
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2037
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getSylius_Repository_LocaleService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1992
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getSylius_LocaleProviderService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2459
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getChang_Locale_Router_LocaleProviderService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1778
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getRouterService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:2189
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getTwigService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getTranslation_ExtractorService.php:18
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getIncenteevTranslationChecker_ExtractorService.php:12
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/getConsole_Command_PublicAlias_IncenteevTranslationChecker_Command_FindMissingService.php:12
require() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:976
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->load() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:243
Symfony\Component\DependencyInjection\Container->make() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:225
Symfony\Component\DependencyInjection\Container->get() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:186
Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:69
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /Users/dos/GitHub/phpmob/takeoff/bin/console:33

// Clearing the cache for the dev environment with debug true

// Clearing outdated warmup directory...

// Warming up cache...

11:05:40 INFO [php] User Deprecated: The "Sylius\Bundle\UserBundle\Controller\SecurityController" class extends "Symfony\Bundle\FrameworkBundle\Controller\Controller" that is deprecated since Symfony 4.2, use {@see AbstractController} instead.
*.
[
"exception" => ErrorException {
#message: """
User Deprecated: The "Sylius\Bundle\UserBundle\Controller\SecurityController" class extends "Symfony\Bundle\FrameworkBundle\Controller\Controller" that is deprecated since Symfony 4.2, use {@see AbstractController} instead.\n
*.
"""
#code: 0
#file: "./vendor/symfony/debug/DebugClassLoader.php"
#line: 191
#severity: E_USER_DEPRECATED
trace: {
./vendor/symfony/debug/DebugClassLoader.php:191 { …}
spl_autoload_call() {}
./vendor/symfony/config/Resource/ClassExistenceResource.php:76 { …}
./vendor/symfony/dependency-injection/ContainerBuilder.php:351 { …}
./vendor/symfony/dependency-injection/Dumper/PhpDumper.php:398 { …}
./vendor/symfony/dependency-injection/Dumper/PhpDumper.php:460 { …}
./vendor/symfony/dependency-injection/Dumper/PhpDumper.php:686 { …}
./vendor/symfony/dependency-injection/Dumper/PhpDumper.php:832 { …}
./vendor/symfony/dependency-injection/Dumper/PhpDumper.php:220 { …}
./vendor/symfony/http-kernel/Kernel.php:735 { …}
./vendor/symfony/http-kernel/Kernel.php:566 { …}
./vendor/symfony/http-kernel/Kernel.php:133 { …}
./vendor/symfony/http-kernel/Kernel.php:150 { …}
./vendor/symfony/framework-bundle/Command/CacheClearCommand.php:187 { …}
./vendor/symfony/framework-bundle/Command/CacheClearCommand.php:129 { …}
./vendor/symfony/console/Command/Command.php:255 { …}
./vendor/symfony/console/Application.php:919 { …}
./vendor/symfony/framework-bundle/Console/Application.php:89 { …}
./vendor/symfony/console/Application.php:262 { …}
./vendor/symfony/framework-bundle/Console/Application.php:75 { …}
./vendor/symfony/console/Application.php:145 { …}
./bin/console:33 {
› $application = new Application($kernel);
› $application->run($input);

}
}
}
]
11:05:40 DEBUG [php] Warning: unlink(/Users/dos/GitHub/phpmob/takeoff/var/cache/de_/ContainerZxXr6Kn.legacy): No such file or directory
[
"exception" => Symfony\Component\Debug\Exception\SilencedErrorContext {
+count: 1
-severity: E_WARNING
trace: {
./vendor/symfony/http-kernel/Kernel.php:746 { …}
./vendor/symfony/http-kernel/Kernel.php:566 { …}
}
}
]

In ContainerAwareEventManager.php line 103:

[RuntimeException]
Adding lazy-loading listeners after construction is not supported.

Exception trace:
() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/doctrine-bridge/ContainerAwareEventManager.php:103
Symfony\Bridge\Doctrine\ContainerAwareEventManager->addEventListener() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1116
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Dbal_DefaultConnectionService() at /Users/dos/GitHub/phpmob/takeoff/var/cache/dev/ContainerZxXr6Kn/TakeOffTakeOff_KernelDevDebugContainer.php:1132
ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer->getDoctrine_Orm_DefaultEntityManagerService() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:245
Symfony\Component\DependencyInjection\Container->make() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/dependency-injection/Container.php:225
Symfony\Component\DependencyInjection\Container->get() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/doctrine-bridge/ManagerRegistry.php:35
Symfony\Bridge\Doctrine\ManagerRegistry->getService() at /Users/dos/GitHub/phpmob/takeoff/vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/AbstractManagerRegistry.php:202
Doctrine\Common\Persistence\AbstractManagerRegistry->getManagers() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/doctrine-bridge/CacheWarmer/ProxyCacheWarmer.php:49
Symfony\Bridge\Doctrine\CacheWarmer\ProxyCacheWarmer->warmUp() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/http-kernel/CacheWarmer/CacheWarmerAggregate.php:96
Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate->warmUp() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/http-kernel/Kernel.php:587
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/http-kernel/Kernel.php:133
Symfony\Component\HttpKernel\Kernel->boot() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/http-kernel/Kernel.php:150
Symfony\Component\HttpKernel\Kernel->reboot() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:187
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Command/CacheClearCommand.php:129
Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Application.php:919
Symfony\Component\Console\Application->doRunCommand() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:89
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Application.php:262
Symfony\Component\Console\Application->doRun() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/framework-bundle/Console/Application.php:75
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/dos/GitHub/phpmob/takeoff/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /Users/dos/GitHub/phpmob/takeoff/bin/console:33

cache:clear [--no-warmup] [--no-optional-warmers] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--]

Here is container file. \ContainerZxXr6Kn\TakeOffTakeOff_KernelDevDebugContainer.php

protected function getDoctrine_Dbal_DefaultConnectionService()
    {
        $a = new \Doctrine\DBAL\Configuration();

        $b = new \Doctrine\DBAL\Logging\LoggerChain();
        $b->addLogger(($this->privates['doctrine.dbal.logger'] ?? $this->getDoctrine_Dbal_LoggerService()));
        $b->addLogger(($this->privates['doctrine.dbal.logger.profiling.default'] ?? ($this->privates['doctrine.dbal.logger.profiling.default'] = new \Doctrine\DBAL\Logging\DebugStack())));

        $a->setSQLLogger($b);
        $c = new \Symfony\Bridge\Doctrine\ContainerAwareEventManager(new \Symfony\Component\DependencyInjection\Argument\ServiceLocator($this->getService, array(
            'doctrine.orm.default_listeners.attach_entity_listeners' => array('privates', 'doctrine.orm.default_listeners.attach_entity_listeners', 'getDoctrine_Orm_DefaultListeners_AttachEntityListenersService.php', true),
            'doctrine.orm.listeners.resolve_target_entity' => array('privates', 'doctrine.orm.listeners.resolve_target_entity', 'getDoctrine_Orm_Listeners_ResolveTargetEntityService.php', true),
            'phpmob.listener.doctrine_event_manager_image_type' => array('privates', 'phpmob.listener.doctrine_event_manager_image_type', 'getPhpmob_Listener_DoctrineEventManagerImageTypeService.php', true),
            'sylius.listener.password_updater' => array('services', 'sylius.listener.password_updater', 'getSylius_Listener_PasswordUpdaterService.php', true),
        )));

        $this->services['doctrine.dbal.default_connection'] = $instance = ($this->privates['doctrine.dbal.connection_factory'] ?? $this->getDoctrine_Dbal_ConnectionFactoryService())->createConnection(array('driver' => 'pdo_mysql', 'charset' => 'utf8mb4', 'url' => $this->getEnv('resolve:DATABASE_URL'), 'host' => 'localhost', 'port' => NULL, 'user' => 'root', 'password' => NULL, 'driverOptions' => array(), 'serverVersion' => '10.3.10', 'defaultTableOptions' => array('charset' => 'utf8mb4', 'collate' => 'utf8mb4_unicode_ci')), $a, $c, array());
        $d = new \Gedmo\SoftDeleteable\SoftDeleteableListener();

        $e = ($this->privates['annotations.cached_reader'] ?? $this->getAnnotations_CachedReaderService());

        $d->setAnnotationReader($e);
        $f = new \Gedmo\Sluggable\SluggableListener();
        $f->setAnnotationReader($e);
        $g = new \Gedmo\Sortable\SortableListener();
        $g->setAnnotationReader($e);
        $h = new \Gedmo\Timestampable\TimestampableListener();
        $h->setAnnotationReader($e);
        $i = new \Gedmo\Tree\TreeListener();
        $i->setAnnotationReader($e);

        $c->addEventSubscriber(($this->services['sylius.event_subscriber.orm_mapped_super_class'] ?? $this->getSylius_EventSubscriber_OrmMappedSuperClassService()));
        $c->addEventSubscriber(($this->services['sylius.event_subscriber.orm_repository_class'] ?? $this->getSylius_EventSubscriber_OrmRepositoryClassService()));
        $c->addEventSubscriber(($this->services['sylius.translation.translatable_listener.doctrine.orm'] ?? $this->getSylius_Translation_TranslatableListener_Doctrine_OrmService()));
        $c->addEventSubscriber(($this->privates['phpmob.tagging.subscriber'] ?? ($this->privates['phpmob.tagging.subscriber'] = new \Chang\Tagging\EventListener\ORMTagSubscriber($this))));
        $c->addEventSubscriber(($this->privates['stof_doctrine_extensions.listener.loggable'] ?? $this->getStofDoctrineExtensions_Listener_LoggableService()));
        $c->addEventSubscriber(($this->privates['chang.messenger.message_recipient_subscriber'] ?? ($this->privates['chang.messenger.message_recipient_subscriber'] = new \Chang\Messenger\EventListener\MessageRecipientSubscriber())));
        $c->addEventSubscriber(($this->privates['chang.locale.locale_event_subscriber'] ?? $this->getChang_Locale_LocaleEventSubscriberService()));
        $c->addEventSubscriber(($this->privates['chang.user.listener.default_username'] ?? $this->getChang_User_Listener_DefaultUsernameService()));
        $c->addEventSubscriber(($this->privates['phpmob.listener.upload_file'] ?? $this->getPhpmob_Listener_UploadFileService()));
        $c->addEventSubscriber($d);
        $c->addEventSubscriber($f);
        $c->addEventSubscriber($g);
        $c->addEventSubscriber($h);
        $c->addEventSubscriber($i);
        $c->addEventListener(array(0 => 'imageTypeRegistry'), 'phpmob.listener.doctrine_event_manager_image_type');
        $c->addEventListener(array(0 => 'loadClassMetadata'), 'doctrine.orm.listeners.resolve_target_entity');
        $c->addEventListener(array(0 => 'loadClassMetadata'), 'doctrine.orm.default_listeners.attach_entity_listeners');
        $c->addEventListener(array(0 => 'prePersist'), 'sylius.listener.password_updater');
        $c->addEventListener(array(0 => 'preUpdate'), 'sylius.listener.password_updater');

        return $instance;
    }

@liverbool
Copy link
Contributor Author

@chalasr @xabbuh What is this error mean?

liverbool added a commit to liverbool/doctrine-lazy-error that referenced this issue Dec 19, 2018
@liverbool
Copy link
Contributor Author

@xabbuh
Copy link
Member

xabbuh commented Dec 19, 2018

The issue here is that one of the event subscribers depends on a Doctrine repository. To construct this repository, the class metadata are read which triggers the loadClassMetadata event leading to the event manager to not accept and further addition of event listeners/subscribers.

Are you sure that only updating Symfony leads to this behaviour? Or did you also update other packages?

@xabbuh
Copy link
Member

xabbuh commented Dec 19, 2018

I can see the same behaviour when downgrading the Symfony related packages in your example application to 4.1.

@liverbool
Copy link
Contributor Author

I think this may depend on sylius/sylius-resource bundle, this error gone away when i remove that bundle.
@pamil do you have some idea?

@liverbool
Copy link
Contributor Author

SF 4.1 is fine! everything is ok.

@xabbuh here is 4.1 downgrade version liverbool/doctrine-lazy-error-41@dd1ae70

@liverbool
Copy link
Contributor Author

liverbool commented Dec 26, 2018

I try to update vendor one by one and finally conclusion is:

symfony/dependency-injection:4.1.7 OK
symfony/dependency-injection:4.1.8 Failed

@liverbool
Copy link
Contributor Author

Here is @nicolas-grekas 's commit (symfony/dependency-injection@5ec6098#diff-5ad937deffee147ff6e4789f46af72d2) that is the cause of this error.

@xabbuh
Copy link
Member

xabbuh commented Jan 11, 2019

Could this also be related to #29836?

@liverbool
Copy link
Contributor Author

I think no!

nicolas-grekas added a commit that referenced this issue Jan 30, 2019
…kas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix dumping Doctrine-like service graphs

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30017 #29637 #29693
| License       | MIT
| Doc PR        | -

I'm unable to provide a reproducer for this, the required service reference graph is too crazy, but that does the job :)

Commits
-------

ed96830 [DI] Fix dumping Doctrine-like service graphs
@liverbool
Copy link
Contributor Author

Still not fix (liverbool/doctrine-lazy-error@aadb9cd)

screen shot 2562-02-04 at 18 01 15

cc @nicolas-grekas

@cirykpopeye
Copy link

I've had this exact same error response, but it was because I created a Twig Extension using the \Twig_extension to extend my custom class. I replaced it with Twig\Extension\AbstractExtension and it that removed my error. Don't know if this case is related though but worth the try since that's the exact error response.

@liverbool
Copy link
Contributor Author

Thanks @cirykpopeye but after tried i have no luck! 😢

@cirykpopeye
Copy link

cirykpopeye commented Feb 5, 2019

@liverbool , I'm in the same boat now. Remove the extension solves the issue so it has something to do with it. I'm only using the router interface inside though.

EDIT: I fixed it by not loading any services in the constructor, and only called them when twig needs them. It's a feature for lazy loading services.

@liverbool
Copy link
Contributor Author

@cirykpopeye sound do i need to inject service container?

@cirykpopeye
Copy link

cirykpopeye commented Feb 5, 2019

@liverbool The main point is that you can't use any of the services in your constructor. You can load them already but using them will cause the error since they're lazy loaded. Use them from you filters/functions directly.

So instead of __construct(Router $router) { $this->router = $router; $this->adminURI = $this->router->generate(...); } you should call the generate function anywhere but the constructor. You can nest that function in a private method so you can keep your code dry though.

@liverbool
Copy link
Contributor Author

I think i have no code like that in constructor.
I found my DoctrineSubscriber depends on SomeRepository, that is case of this error!

@nicolas-grekas nicolas-grekas reopened this Feb 6, 2019
nicolas-grekas added a commit that referenced this issue Jul 29, 2019
…rryan, nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix dumping Doctrine-like service graphs (bis)

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30091, #29637
| License       | MIT
| Doc PR        | -

Dumping the container while accounting for circular references is hard :)

Commits
-------

a37f3e0 [DI] Fix dumping Doctrine-like service graphs (bis)
ee49144 Failing test case for complex near-circular situation + lazy
@nicolas-grekas
Copy link
Member

Fix is now merged, please report back if you still encounter the issue (and open a new issue with a reproducer please if that happens.)

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

6 participants