Problem/Motivation
See comment #4 for full details, but in short:
When installing a module, the container gets rebuilt before the .install and .module files are included. This means that any class_alias calls in those files are not processed yet when the container reads out the services files. If any code subscribes to a kernel event, it may lead to services being loaded for which a class alias was used, leading to a "Class not found" exception.
Proposed resolution
Switch these 2 pieces of code around:
// Update the kernel to include it.
$this->updateKernel($module_filenames);
// Load the module's .module and .install files.
$this->moduleHandler->load($module);
$this->moduleHandler->loadInclude($module, 'install');
Original report
Problem/Motivation
After upgrading to Drupal core 10.2, when I try and do a clean site install from the site configuration it fails with the following error.
[error] Error: Class "Drupal\variationcache\Cache\VariationCacheFactory" not found in Drupal\Component\DependencyInjection\Container->createService() (line 259 of /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php) #0 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'variation_cache...')
#1 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('variation_cache...', 1)
#2 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'render_cache')
#4 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('render_cache', 1)
#5 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#6 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'renderer')
#7 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('renderer', 1)
#8 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#9 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'eca.service.tok...')
#10 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('eca.service.tok...', 1)
#11 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#12 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'eca_misc.subscr...')
#13 /REDACTED/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\Component\DependencyInjection\Container->get('eca_misc.subscr...')
#14 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(992): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Component\EventDispatcher\Event), 'kernel.containe...')
#15 /app/vendor/drush/drush/src/Drupal/DrupalKernelTrait.php(72): Drupal\Core\DrupalKernel->initializeContainer()
#16 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(816): Drush\Drupal\DrupalKernel->initializeContainer()
#17 /REDACTED/core/lib/Drupal/Core/Extension/ModuleInstaller.php(615): Drupal\Core\DrupalKernel->updateModules(Array, Array)
#18 /REDACTED/core/lib/Drupal/Core/Extension/ModuleInstaller.php(251): Drupal\Core\Extension\ModuleInstaller->updateKernel(Array)
#19 /REDACTED/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install(Array, false)
#20 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(872): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array, false)
#21 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(624): Drupal\Core\Config\ConfigImporter->processExtension('module', 'install', 'variationcache')
#22 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processExtensions(Array)
#23 /app/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(259): Drupal\Core\Config\ConfigImporter->doSyncStep('processExtensio...', Array)
#24 /app/vendor/drush/drush/includes/drush.inc(62): Drush\Commands\config\ConfigImportCommands->doImport(Object(Drupal\Core\Config\StorageComparer))
#25 /app/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array(Array, Array)
#26 /app/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(230): drush_op(Array, Object(Drupal\Core\Config\StorageComparer))
#27 [internal function]: Drush\Commands\config\ConfigImportCommands->import(Array)
#28 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#29 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#30 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#31 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#32 /app/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /app/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /app/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /app/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /app/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /app/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /app/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#39 /app/vendor/drush/drush/drush(4): require('/app/vendor/dru...')
#40 /app/vendor/bin/drush(119): include('/app/vendor/dru...')
#41 {main}.
Error: Class "Drupal\variationcache\Cache\VariationCacheFactory" not found in /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 #0 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'variation_cache...')
#1 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('variation_cache...', 1)
#2 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#3 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'render_cache')
#4 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('render_cache', 1)
#5 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#6 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'renderer')
#7 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('renderer', 1)
#8 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#9 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'eca.service.tok...')
#10 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(440): Drupal\Component\DependencyInjection\Container->get('eca.service.tok...', 1)
#11 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(237): Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array)
#12 /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService(Array, 'eca_misc.subscr...')
#13 /REDACTED/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\Component\DependencyInjection\Container->get('eca_misc.subscr...')
#14 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(992): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Component\EventDispatcher\Event), 'kernel.containe...')
#15 /app/vendor/drush/drush/src/Drupal/DrupalKernelTrait.php(72): Drupal\Core\DrupalKernel->initializeContainer()
#16 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(816): Drush\Drupal\DrupalKernel->initializeContainer()
#17 /REDACTED/core/lib/Drupal/Core/Extension/ModuleInstaller.php(615): Drupal\Core\DrupalKernel->updateModules(Array, Array)
#18 /REDACTED/core/lib/Drupal/Core/Extension/ModuleInstaller.php(251): Drupal\Core\Extension\ModuleInstaller->updateKernel(Array)
#19 /REDACTED/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install(Array, false)
#20 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(872): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array, false)
#21 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(624): Drupal\Core\Config\ConfigImporter->processExtension('module', 'install', 'variationcache')
#22 /REDACTED/core/lib/Drupal/Core/Config/ConfigImporter.php(561): Drupal\Core\Config\ConfigImporter->processExtensions(Array)
#23 /app/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(259): Drupal\Core\Config\ConfigImporter->doSyncStep('processExtensio...', Array)
#24 /app/vendor/drush/drush/includes/drush.inc(62): Drush\Commands\config\ConfigImportCommands->doImport(Object(Drupal\Core\Config\StorageComparer))
#25 /app/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array(Array, Array)
#26 /app/vendor/drush/drush/src/Commands/config/ConfigImportCommands.php(230): drush_op(Array, Object(Drupal\Core\Config\StorageComparer))
#27 [internal function]: Drush\Commands\config\ConfigImportCommands->import(Array)
#28 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#29 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#30 /app/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#31 /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#32 /app/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 /app/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 /app/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#35 /app/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#36 /app/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#37 /app/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#38 /app/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#39 /app/vendor/drush/drush/drush(4): require('/app/vendor/dru...')
#40 /app/vendor/bin/drush(119): include('/app/vendor/dru...')
#41 {main}
Error: Class "Drupal\variationcache\Cache\VariationCacheFactory" not found in Drupal\Component\DependencyInjection\Container->createService() (line 259 of /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php).
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "eca_misc.subscriber", path: "eca_misc.subscriber -> eca.service.token -> renderer -> render_cache -> variation_cache_factory". in /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php:147
Stack trace:
#0 /REDACTED/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\Component\DependencyInjection\Container->get('eca_misc.subscr...')
#1 /app/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...')
#2 /REDACTED/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#3 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#4 /app/vendor/drush/drush/src/Boot/DrupalBoot8.php(326): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#5 [internal function]: Drush\Boot\DrupalBoot8->terminate()
#6 {main}
thrown in /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php on line 147
PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "eca_misc.subscriber", path: "eca_misc.subscriber -> eca.service.token -> renderer -> render_cache -> variation_cache_factory". in /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php:147
Stack trace:
#0 /REDACTED/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(105): Drupal\Component\DependencyInjection\Container->get('eca_misc.subscr...')
#1 /app/vendor/symfony/http-kernel/HttpKernel.php(115): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\TerminateEvent), 'kernel.terminat...')
#2 /REDACTED/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(63): Symfony\Component\HttpKernel\HttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#3 /REDACTED/core/lib/Drupal/Core/DrupalKernel.php(688): Drupal\Core\StackMiddleware\StackedHttpKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#4 /app/vendor/drush/drush/src/Boot/DrupalBoot8.php(326): Drupal\Core\DrupalKernel->terminate(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Render\HtmlResponse))
#5 [internal function]: Drush\Boot\DrupalBoot8->terminate()
#6 {main}
thrown in /REDACTED/core/lib/Drupal/Component/DependencyInjection/Container.php on line 147
I'm assuming this is related to the new variation cache cache added to 10.2:
https://www.drupal.org/node/3365546 β
I do also have the Groups module 3.x installed which uses the flexible_permissions and contrib variationcache modules. Even with those modules installed however, if I don't have the ECA Miscellaneous module installed, the issue doesn't occur.
Steps to reproduce
- Upgrade to Drupal 10.2
- Have the ECA Miscellaneous module installed.
- Do a clean site install from configuration:
drush si --existing-config
- The install should fail.
- Uninstall the EECA Miscellaneous module.
- Do a clean site install from configuration again:
drush si --existing-config
- The install should succeed.