class_alias calls not available when rebuilding container in ModuleInstaller

Created on 8 January 2024, about 1 year ago
Updated 18 January 2024, about 1 year ago

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

  1. Upgrade to Drupal 10.2
  2. Have the ECA Miscellaneous module installed.
  3. Do a clean site install from configuration: drush si --existing-config
  4. The install should fail.
  5. Uninstall the EECA Miscellaneous module.
  6. Do a clean site install from configuration again: drush si --existing-config
  7. The install should succeed.
πŸ› Bug report
Status

Active

Version

10.2 ✨

Component
BaseΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States pcate

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @pcate
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Do a clean site install from configuration: drush si --existing-config

    I wouldn't call that a "clean site installation". This is installing a new site from existing config, which can contain all sort of stuff, which is not a clean Drupal 10.2 installation.

    The circular reference you experience here might be a follow-up error from the first one, which is this:

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

    I've looked into that module variationcache which defines the services variation_cache_factory. That is part of the circular reference that's being reported, but the class that service is referring to, doesn't exist. It's defined as a class alias in a module file that's not yet loaded when services get initialized.

    You may want to try without that variationcache module or ask there, if that can be fixed somehow.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    From module installer:

            // 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');
    

    So it should include variationcache.module and therefore find the class_alias calls, but instead it first tries to read the services files and then loads the module and install file, which is too late. So this might be a core bug we're looking at.

    Having said that, I'm curious as to why this doesn't fail with clean Group installs and does with ECA.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    I think I see what's happening.

    ECA subscribes to kernel events, which are fired during container build. This leads to a series of dependencies ending up at variation_cache_factory, which since core 10.2 exists both in core.services.yml and variationcache.services.yml, with the latter counting as a decorator.

    The contrib module's services file is found before the module file is enabled and normally that would be okay because the service does not get initialized during the module's install. But because of the event subscriber trying to initialize it through its dependencies and the class_alias call not being declared yet, it fails.

    We can fix this in core by first including the module and install file and then rebuilding the container, or we can fix this in VC by using a ServiceProvider to declare the service only when core's variation_cache_factory service does not exist (i.e. you're on core < 10.2). Given how this might occur for more than just VC, I'm inclined to aim for a fix in core.

    class_alias is actively encouraged in core to work around BC breaks, so I'd expect the module installer to support this.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Drupal\Tests\system\Functional\Module\ClassLoaderTest::testAutoloadFromModuleFile fails, output (from the artifacts):

    The website encountered an unexpected error. Try again later.
    
    Error: Class "Drupal\module_autoload_test\SomeClass" not found in include_once() (line 10 of core/modules/system/tests/modules/module_autoload_test/module_autoload_test.module).
    
    Drupal\Core\Extension\Extension->load() (Line: 128)
    Drupal\Core\Extension\ModuleHandler->load('module_autoload_test') (Line: 251)
    Drupal\Core\Extension\ModuleInstaller->install(Array, 1) (Line: 83)
    Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array) (Line: 502)
    Drupal\system\Form\ModulesListForm->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('system_modules', Array, Object) (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 37)
    Drupal\Core\Test\StackMiddleware\TestWaitTerminateMiddleware->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    

    Digging deeper

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Ugh, so swapping the code around means the module file is included before updateKernel is called, which in turn calls $this->kernel->updateModules($module_filenames, $module_filenames); where the namespaces are registered and the container is rebuilt. The fact that the namespaces aren't registered yet makes that test fail.

    If we want to fix this in core, we'd need to tear this code apart and first register namespaces, then include module/install file and only then rebuild the container.

    I'm starting to think this is a lot of work for an absolute edge case, the conditions are as follows:

    1. Module A has an event subscriber to kernel events
    2. Said event subscriber has a few core services as dependencies
    3. Module B is installed and decorates one of these core services with a class aliased class
    4. The class_alias call is inside Module B's .module file, which hasn't been loaded at the time the kernel event subscriber is called

    Ideally, this is fixed in core as we claim to support class_alias but clearly don't, but the work required might be out of proportion compared to how rare this bug is and how comparatively easy it is perhaps to fix in module B (contrib VariationCache).

    Will drop this in Drupal Slack and ask for more opinions.

  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    A simple way to test this is to write a test module that has:

    1. A class in the src folder
    2. A class_alias to said class in the module file
    3. An EventSubscriber to kernel events in the services.yml file using the alias for the class

    Trying to install that module should fail as it registers an at-the-time non-existent class alias and tries to instantiate that service (as it's an event subscriber and kernel events are fired), leading to a class not found exception.

  • πŸ‡©πŸ‡ͺGermany rgpublic DΓΌsseldorf πŸ‡©πŸ‡ͺ πŸ‡ͺπŸ‡Ί

    If someone gets this error for a stand-alone CLI script. The quick solution (for me) was:

    \Drupal::moduleHandler()->load('variationcache');

    after $kernel->boot();

    Hope this is helpful for some.

Production build 0.71.5 2024