diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStore.php b/core/lib/Drupal/Core/TempStore/SharedTempStore.php index 90572d8bba..e064d7d97f 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStore.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStore.php @@ -310,7 +310,9 @@ public function deleteIfOwner($key) { * This method should be called when a value is set. */ protected function ensureAnonymousSession() { - if ($this->currentUser->isAnonymous()) { + // If this is being run from the CLI then the request will not have + // session. + if ($this->currentUser->isAnonymous() && $this->requestStack->getCurrentRequest()->hasSession()) { $this->requestStack->getCurrentRequest()->getSession()->set('core.tempstore.shared.owner', $this->owner); } }