Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck()

Created on 27 March 2024, 3 months ago
Updated 16 April 2024, 2 months ago

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 141 of /var/www/html/docroot/core/lib/Drupal/Core/Entity/Query/Sql/Query.php)
#0 /var/www/html/docroot/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(80): Drupal\Core\Entity\Query\Sql\Query->prepare()
#1 /var/www/html/docroot/modules/contrib/votingapi/src/VoteResultStorage.php(28): Drupal\Core\Entity\Query\Sql\Query->execute()

🐛 Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇺🇦Ukraine Bobik

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

Merge Requests

Comments & Activities

  • Issue created by @Bobik
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 3 months ago
    10 pass
  • 🇺🇦Ukraine Bobik

    I've fixed the issue. Check it

  • Pipeline finished with Success
    3 months ago
    Total: 158s
    #130494
  • 🇮🇳India Raveen Kumar

    @bobi, you're calling the accessCheck() method without passing any arguments. By default, Drupal will perform access checking if you don't specify anything, so calling ->accessCheck() without arguments is equivalent to ->accessCheck(TRUE)

  • Status changed to Needs review 3 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 3 months ago
    10 pass
  • Status changed to Postponed: needs info 3 months ago
  • 🇺🇸United States TR Cascadia

    Look at the code - accessCheck() is already in there and has been in there for a long time. How did you get this error?

  • Issue was unassigned.
  • Status changed to Needs review 3 months ago
  • 🇺🇦Ukraine Bobik

    Hi

    @Raveen Thakur
    The method accessCheck() has the default value TRUE
    @see web/core/lib/Drupal/Core/Entity/Query/QueryInterface.php
    If you didn't have any parameters access checking will enabled

    @TR
    I've chacked once again my site and the Voting API module. I using the 8.x-3.0-beta4 version. In this version the getEntityResults() method doesn't have call the accessCheck() method. Also, I've checked the dev version of the module. The accessCheck() really exists in it. It something strange why these changes didn't include the latest release of the module. The patch is solving the problem to the next release

  • 🇬🇧United Kingdom aaron.ferris

    Also noticing this issue, by way of the like_and_dislike module.

    The access check is there for VoteStorage, but not VoteResultStorage unless im missing something. This patch is for VoteResultStorage.

  • Status changed to Closed: works as designed 2 months ago
  • 🇺🇸United States TR Cascadia

    That's not how Deepak works. Beta4 can't be changed my dudes go in -dev, and -dev is already correct in this case.

  • 🇬🇧United Kingdom aaron.ferris

    This change isn't in -dev, or -beta.

    Dev

    /**
     * Storage class for vote entities.
     *
     * This extends the \Drupal\entity\EntityDatabaseStorage class, adding
     * required special handling for vote entities.
     */
    class VoteResultStorage extends SqlContentEntityStorage implements VoteResultStorageInterface {
    
      /**
       * {@inheritdoc}
       */
      public function getEntityResults($entity_type_id, $entity_id, $vote_type, $function) {
        $query = \Drupal::entityQuery('vote_result')
          ->condition('entity_type', $entity_type_id)
          ->condition('entity_id', $entity_id)
          ->condition('type', $vote_type);
        if (!empty($function)) {
          $query->condition('function', $function);
        }
        $query->sort('type');
        $query->accessCheck(TRUE);
        $vote_ids = $query->execute();
        return VoteResult::loadMultiple($vote_ids);
      }
    
    }
    
Production build 0.69.0 2024