-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Comments
Can you please add the full stack trace to your description? (including the caller) |
I have nothing special just upgrade 4.1 to 4.2 (from old project) and got an error on |
Can you run the command with the |
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. |
@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
sf cach:c -vvv
[WARNING] Some commands could not be registered: In ContainerAwareEventManager.php line 103: [RuntimeException] Exception trace: [WARNING] Some commands could not be registered: In ContainerAwareEventManager.php line 103: [RuntimeException] Exception trace: // 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. In ContainerAwareEventManager.php line 103: [RuntimeException] Exception trace: 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. 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;
} |
@chalasr @xabbuh Here is my commit to produce this error liverbool/doctrine-lazy-error@aadb9cd Here services i config https://github.com/liverbool/doctrine-lazy-error/blob/aadb9cd3b5bbca46d144757b653e8f2c9b18283e/config/services.yaml |
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 Are you sure that only updating Symfony leads to this behaviour? Or did you also update other packages? |
I can see the same behaviour when downgrading the Symfony related packages in your example application to 4.1. |
I think this may depend on |
SF 4.1 is fine! everything is ok. @xabbuh here is 4.1 downgrade version liverbool/doctrine-lazy-error-41@dd1ae70 |
I try to update vendor one by one and finally conclusion is:
|
Here is @nicolas-grekas 's commit (symfony/dependency-injection@5ec6098#diff-5ad937deffee147ff6e4789f46af72d2) that is the cause of this error. |
Could this also be related to #29836? |
I think no! |
…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
Still not fix (liverbool/doctrine-lazy-error@aadb9cd) |
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. |
Thanks @cirykpopeye but after tried i have no luck! 😢 |
@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. |
@cirykpopeye sound do i need to inject service container? |
@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. |
I think i have no code like that in constructor. |
…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
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.) |
After upgrade from 4.1 to 4.2 i ran into this error when cache clear process.
I have no idea to fix it, Have someone can spot me for fixing?
Thanks!
The text was updated successfully, but these errors were encountered: