I have a simple bit of test code to load nodes by UUID:
$uuids = ['5e331255-adf6-423e-a355-dc02c621ffcd'];
$nids = \Drupal::entityTypeManager()->getStorage('node')
->getQuery()
->condition('uuid', $uuids, 'IN')
->execute();
When I execute this code in hook_page_attachments_alter()
, or anywhere else in a rendered page build, $nids
is populated as expected with the correct node ID.
When I execute exactly the same code, verbatim, in a drush command, $nids
is empty.
Loading the node by ID works fine in both contexts:
$node = \Drupal::entityTypeManager()->getStorage('node')->load(12345);
This happens with the same code/database in multiple environments (Lando, ACSF, standard LAMP), and I've confirmed that drush is connecting to the correct database everywhere.
Are there any obvious properties of the node or storage system, or configuration of drush, which could be responsible for this?
Content moderation, revisions, and translations are all enabled for the node's content type, in case it matters.
->accessCheck(FALSE)