\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.

Created on 7 January 2025, 2 months ago

Problem/Motivation

When running Drush 13.3.3.0 on D11 the following error message

docker@cli:/var/www$ drush updb

In Drupal.php line 169:
                                                                                                             
  \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.  
                                                                                                             

docker@cli:/var/www$ drush -vvv updb
 [preflight] Config paths: /var/www/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /var/www/web/drush/sites,/var/www/drush/sites
 [preflight] Commandfile search paths: /var/www/vendor/drush/drush/src,/var/www/drush
 [info] Starting bootstrap to full [1.03 sec, 11.25 MB]
 [info] Drush bootstrap phase 5 [1.03 sec, 11.25 MB]
 [info] Try to validate bootstrap phase 5 [1.03 sec, 11.25 MB]
 [info] Try to validate bootstrap phase 5 [1.03 sec, 11.25 MB]
 [info] Try to bootstrap at phase 5 [1.03 sec, 11.25 MB]
 [info] Drush bootstrap phase: bootstrapDrupalRoot() [1.03 sec, 11.25 MB]
 [info] Change working directory to /var/www/web [1.03 sec, 11.25 MB]
 [info] Initialized Drupal 11.1.0 root directory at /var/www/web [1.03 sec, 11.3 MB]
 [info] Try to validate bootstrap phase 5 [1.03 sec, 11.3 MB]
 [info] Try to bootstrap at phase 5 [1.03 sec, 11.75 MB]
 [info] Drush bootstrap phase: bootstrapDrupalSite() [1.03 sec, 11.75 MB]
 [debug] Could not find a Drush config file at sites/default/drush.yml. [1.03 sec, 12.54 MB]
 [info] Initialized Drupal site rbht-d11.docksal.site at sites/default [1.03 sec, 12.54 MB]
 [info] Try to validate bootstrap phase 5 [1.03 sec, 12.54 MB]
 [info] Try to bootstrap at phase 5 [1.03 sec, 12.54 MB]
 [info] Drush bootstrap phase: bootstrapDrupalConfiguration() [1.03 sec, 12.54 MB]
 [info] Try to validate bootstrap phase 5 [1.04 sec, 12.82 MB]
 [info] Try to bootstrap at phase 5 [1.04 sec, 13.35 MB]
 [info] Drush bootstrap phase: bootstrapDrupalDatabase() [1.04 sec, 13.35 MB]
 [info] Successfully connected to the Drupal database. [1.04 sec, 13.35 MB]
 [info] Try to validate bootstrap phase 5 [1.04 sec, 13.35 MB]
 [info] Try to bootstrap at phase 5 [1.04 sec, 13.35 MB]
 [info] Drush bootstrap phase: bootstrapDrupalFull() [1.04 sec, 13.35 MB]
 [debug] Start bootstrap of the Drupal Kernel. [1.04 sec, 13.35 MB]

In Drupal.php line 169:
                                                                                                             
  [Drupal\Core\DependencyInjection\ContainerNotInitializedException]                                         
  \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.  
                                                                                                             

Exception trace:
  at /var/www/web/core/lib/Drupal.php:169
 Drupal::getContainer() at /var/www/web/core/lib/Drupal.php:197
 Drupal::service() at /var/www/web/modules/contrib/workbench_moderation/workbench_moderation.module:54
 workbench_moderation_module_implements_alter() at /var/www/web/core/lib/Drupal/Core/Hook/HookCollectorPass.php:94
 Drupal\Core\Hook\HookCollectorPass->process() at /var/www/vendor/symfony/dependency-injection/Compiler/Compiler.php:73
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /var/www/vendor/symfony/dependency-injection/ContainerBuilder.php:814
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /var/www/web/core/lib/Drupal/Core/DrupalKernel.php:1380
 Drupal\Core\DrupalKernel->compileContainer() at /var/www/web/core/lib/Drupal/Core/DrupalKernel.php:899
 Drupal\Core\DrupalKernel->initializeContainer() at /var/www/web/core/lib/Drupal/Core/Update/UpdateKernel.php:42
 Drupal\Core\Update\UpdateKernel->initializeContainer() at /var/www/web/core/lib/Drupal/Core/DrupalKernel.php:505
 Drupal\Core\DrupalKernel->boot() at /var/www/vendor/drush/drush/src/Boot/DrupalBoot8.php:209
 Drush\Boot\DrupalBoot8->bootstrapDrupalFull() at /var/www/vendor/drush/drush/src/Boot/BootstrapManager.php:211
 Drush\Boot\BootstrapManager->doBootstrap() at /var/www/vendor/drush/drush/src/Boot/BootstrapManager.php:352
 Drush\Boot\BootstrapManager->bootstrapToPhaseIndex() at /var/www/vendor/drush/drush/src/Boot/BootstrapManager.php:304
 Drush\Boot\BootstrapManager->bootstrapToPhase() at /var/www/vendor/drush/drush/src/Boot/BootstrapHook.php:36
 Drush\Boot\BootstrapHook->initialize() at /var/www/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:44
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->doInitializeHook() at /var/www/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:36
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook() at /var/www/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:29
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize() at /var/www/vendor/consolidation/annotated-command/src/CommandProcessor.php:145
 Consolidation\AnnotatedCommand\CommandProcessor->initializeHook() at /var/www/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:376
 Consolidation\AnnotatedCommand\AnnotatedCommand->initialize() at /var/www/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/console/Application.php:1094
 Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/console/Application.php:342
 Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/console/Application.php:193
 Symfony\Component\Console\Application->run() at /var/www/vendor/drush/drush/src/Runtime/Runtime.php:110
 Drush\Runtime\Runtime->doRun() at /var/www/vendor/drush/drush/src/Runtime/Runtime.php:40
 Drush\Runtime\Runtime->run() at /var/www/vendor/drush/drush/drush.php:140
 include() at /var/www/vendor/bin/drush.php:119

Steps to reproduce

Build a Drupal D11.1.0 and Drush 13.3.3.0 and run the drush updb command.

Proposed resolution

The quick solutions is to move the code from the service to module

/**
 * Implements hook_module_implements_alter().
 */
function workbench_moderation_module_implements_alter(&$implementations, $hook) {
  /** @var \Drupal\workbench_moderation\InlineEditingDisabler $inline_editing_disabler */
  $inline_editing_disabler = \Drupal::service('workbench_moderation.inline_editing_disabler');
  $inline_editing_disabler->moduleImplementsAlter($implementations, $hook);
}

with

/**
 * Implements hook_module_implements_alter().
 */
function workbench_moderation_module_implements_alter(&$implementations, $hook) {
    if ($hook == 'entity_view_alter') {
      // Find the quickedit implementation and move workbench after it.
      unset($implementations['workbench_moderation']);
      $implementations['workbench_moderation'] = FALSE;
    }
}

in workbench_moderation.module

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom somersoft

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024