Problem/Motivation

On Drupal 11.4.7, when running update.php or `drush updb`, where a "hook_update_N" hook updates a content entity which are included in the Search API Index a lot of "Theme hook %hook not found." warnings are given, and the search index is properly not rendered correctly, as the theme hook are not invoked.

This issue seems to have existed all the way back to 10.3.0 - https://www.drupal.org/project/drupal/issues/3441222.
At that point a specific rule for UpdateKernel was made in core/lib/Drupal/Core/Theme/Registry.php:

Line 313 to 331 (for Drupal 11.4.7)

    if ($this->kernel instanceof UpdateKernel) {
      $module_list = $this->moduleHandler->getModuleList();
      $filter_list = array_intersect_key($module_list, ['system' => TRUE]);

      // Call ::build() with only the system module and then revert.
      $this->moduleHandler->setModuleList($filter_list);
      $this->build();
      $this->moduleHandler->setModuleList($module_list);

      // We might have poisoned the cache with only info from 'system'.
      $this->cache->delete("theme_registry:build:modules");
    }
    else {
      $this->build();
      // Only persist it if all modules are loaded to ensure it is complete.
      if ($this->moduleHandler->isLoaded()) {
        $this->setCache();
      }
    }

So only system hooks are loaded into the registry.

Example hook:

/**
Testing 3609212 on Update hook
 */
function testing_3609212_update_11401(): void {
  $logger = \Drupal::logger('testing_3609212_hook');
  $logger->notice('Testing 3609212 on Update hook');
  $n = \Drupal\node\Entity\Node::load(89);
  $n->set('changed', time());
  $n->save();
}

Result:

 ------------ ----------- --------------- ---------------------------------------- 
  Module       Update ID   Type            Description                             
 ------------ ----------- --------------- ---------------------------------------- 
  testing.   11401       hook_update_n   11401 - Testing 3609212 on Update hook  
 ------------ ----------- --------------- ---------------------------------------- 

 // Do you wish to run the specified pending updates?: yes.                                                             

>  [notice] Update started: testing_3609212_update_11401
>  [notice] Testing 3609212 on Update hook
>  [notice] Update completed: testing_3609212_update_11401
>  [warning] Theme hook ds_entity_view not found.
>  [warning] Theme hook username not found.
.....
>  [warning] Theme hook file_link not found.
>  [warning] Theme hook file_link not found.
>  [warning] Theme hook link_formatter_link_separate not found.
>  [warning] Theme hook link_formatter_link_separate not found.
>  [warning] Theme hook link_formatter_link_separate not found.
>  [warning] Theme hook link_formatter_link_separate not found.
 [success] Finished performing updates.

Steps to reproduce

- Install Drupal 11.4.7
- Install Search API
- Setup Search API database and index, where at least one field is the rendered item.
- Setup a node where a more complex content is included, like a file_link field.
- Create an update hook which updates this node.
- Observe the warnings in console or in dblog.

Proposed resolution

Remaining tasks

Comments

flemming.fridthjof created an issue. See original summary.

flemming.fridthjof’s picture

Issue summary: View changes