QueryInterface doesn't work in hook_update_n when triggered by drush

Created on 31 March 2023, over 1 year ago
Updated 2 June 2023, over 1 year ago

Problem/Motivation

\Drupal::entityQuery('node')->execute() return nothing in hook_update_n when triggered by drush.
But it got correct result in hook_update_n if the update was done in web page interface.

Steps to reproduce

In new install Drupal (tested in 9.5.x and 10.0.x) and enable a custom_module

Add hook_update

function custom_module_update_8001() {
  $query = \Drupal::entityQuery('node')->execute();
  print_r($query);
}

Run it with "drush updb", no query result will be returned.
Run it in the browser from localhost/update.php, correct entity ids will be printed.

However, \Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['type' => 'article']) works correctly in both situation.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Closed: works as designed

Version

10.0 ✨

Component
UpdateΒ  β†’

Last updated about 20 hours ago

  • Maintained by
  • πŸ‡ΊπŸ‡ΈUnited States @tedbow
  • πŸ‡ΊπŸ‡ΈUnited States @dww
Created by

πŸ‡¬πŸ‡§United Kingdom shenzhuxi

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

Comments & Activities

Production build 0.71.5 2024