Entity queries must explicitly set whether the query should be access checked or not

Created on 16 August 2023, over 1 year ago
Updated 28 August 2024, 3 months ago

Drupal version : 10.1.2
DB driver : pgsql
PHP version : 8.1.0
Drush version : 12.1.2.0

search_api version: '8.x-1.29'

drush sapi-i my_collection_name --limit 100

>  [error]  Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 162 of /Applications/MAMP/htdocs/core/lib/Drupal/Core/Entity/Query/Sql/Query.php).
>  [error]  Drupal\Core\Entity\EntityStorageException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (line 763 of /Applications/MAMP/htdocs/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
>  [notice] An error occurred during indexing on My Collection Name Index: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck().
>  [error]  Message: Couldn't index items. Check the logs for details.

core/lib/Drupal/Core/Entity/Query/Sql/Query.php

use Drupal\Core\Logger\RfcLogLevel;
...

    \Drupal::logger('custom')->log(RfcLogLevel::DEBUG, $this->sqlQuery->__toString());
    // $e = new \Exception;
    // \Drupal::logger('custom')->error($e->getTraceAsString());
    if (is_null($this->accessCheck)) {
      throw new QueryException('Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck().');
    }

With this log added I see the following:

[Wed, 08/16/2023 - 09:45 EDT] [Debug] [custom] [client: 127.0.0.1, Anonymous] SELECT \nFROM\n@search_api_task "base_table"
[Wed, 08/16/2023 - 09:45 EDT] [Error] [search_api_task] [client: 127.0.0.1, Anonymous] Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 162 of /Applications/MAMP/htdocs/core/lib/Drupal/Core/Entity/Query/Sql/Query.php).
[Wed, 08/16/2023 - 09:45 EDT] [Error] [search_api] [client: 127.0.0.1, Anonymous] Drupal\Core\Entity\EntityStorageException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Sql\SqlContentEntityStorage->delete() (line 763 of /Applications/MAMP/htdocs/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

From what I understand we need to add accessChecks like the following:

diff --git a/modules/contrib/search_api/src/Task/TaskManager.php b/modules/contrib/search_api/src/Task/TaskManager.php
index 1b86a8581..a2d78a18d 100644
--- a/modules/contrib/search_api/src/Task/TaskManager.php
+++ b/modules/contrib/search_api/src/Task/TaskManager.php
@@ -151,7 +151,7 @@ public function addTask($type, ServerInterface $server = NULL, IndexInterface $i
       'server_id' => $server_id,
       'index_id' => $index_id,
       'data' => $data,
-    ])->execute();
+    ])->accessCheck(FALSE)->execute();
     if ($result) {
       return $this->getTaskStorage()->load(reset($result));
     }
@@ -170,7 +170,7 @@ public function addTask($type, ServerInterface $server = NULL, IndexInterface $i
    * {@inheritdoc}
    */
   public function loadTasks(array $conditions = []) {
-    $task_ids = $this->getTasksQuery($conditions)->execute();
+    $task_ids = $this->getTasksQuery($conditions)->accessCheck(FALSE)->execute();
     if ($task_ids) {
       return $this->getTaskStorage()->loadMultiple($task_ids);
     }
@@ -195,6 +195,7 @@ public function deleteTasks(array $conditions = []) {
     while (TRUE) {
       $task_ids = $this->getTasksQuery($conditions)
         ->range(0, 100)
+        ->accessCheck(FALSE)
         ->execute();
       if (!$task_ids) {
         break;
@@ -228,7 +229,7 @@ public function executeSpecificTask(TaskInterface $task) {
    * {@inheritdoc}
    */
   public function executeSingleTask(array $conditions = []) {
-    $task_id = $this->getTasksQuery($conditions)->range(0, 1)->execute();
+    $task_id = $this->getTasksQuery($conditions)->range(0, 1)->accessCheck(FALSE)->execute();
     if ($task_id) {
       $task_id = reset($task_id);
       /** @var \Drupal\search_api\Task\TaskInterface $task */

But so far I have not been able to resolve this.

🐛 Bug report
Status

Closed: duplicate

Version

4.0

Component

Flag core

Created by

🇺🇸United States jakegibs617

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024