Whenever the kernel is rebuilt, a new ModuleHandler instance pops into place, which believes that all modules have not be loaded yet in the current page request...

That is broken. Once modules are loaded, they stay loaded, and the code should reflect that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Status: Active » Needs review
FileSize
407 bytes

Here's some example code that illustrates the problem. It looks like a harmless patch, but I'm pretty sure it will fail tests spectacularly.

The way I actually ran into it was testing the patches in #734710: API functions that invoke hooks don't work as expected when a disabled module is being uninstalled manually, and trying to uninstall a module with the overlay open. You wind up thrown out of the overlay and with an exception thrown that says "theme() may not be called until all modules are loaded".

David_Rothstein’s picture

And here is a possible fix, although I have no idea what the consequences are. You can see that there's existing code (originally added in #1331486: Move module_invoke_*() and friends to an Extensions class) to work around this issue when unit tests are being run, so I tried removing that too.

This patch definitely improves the situation with #734710: API functions that invoke hooks don't work as expected when a disabled module is being uninstalled - no more exceptions thrown when those patches are used, although there is still a weird issue with the toolbar disappearing after a module is uninstalled in the overlay that may or may not be related to this.

Status: Needs review » Needs work

The last submitted patch, module-handler-is-loaded-2084115-2.patch, failed testing.

jhedstrom’s picture

Issue summary: View changes
Status: Needs work » Postponed (maintainer needs more info)

I think with the big refactoring in #2346937: Implement a Renderer service; reduces drupal_render / _theme service container calls, this is no longer an issue. I've tried this code:

/**
 * Implements hook_module_preinstall().
 */
function system_module_preinstall() {
  $renderer = \Drupal::service('renderer');
  $stuff = array('#markup' => 'foo');
  $bar = $renderer->render($stuff);
  drupal_set_message($bar);
}

and cannot reproduce the errors here.

Berdir’s picture

I think this is more related to the split-up of module handler and moduel installer but yes, this might be fixed.

larowlan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing due to inactivity, if this is still an issue - please reopen