D10 onwards not calling accessCheck() is deprecated and must be explicitly set.

Created on 21 September 2023, about 1 year ago

Problem/Motivation

After upgrading to D10, I was unable to save any nodes having voting functionality like "Like - Dislike" and was getting the below 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 141 of /mnt/www/html/devportalode230/docroot/core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

Steps to reproduce

1. Upgrade or be on D10 version.
2. Enable like and dislike module.
3. Add like dislike functionality to article content type.
4. Try to create and save a new article.

Proposed resolution

It was found that D10 onwards, while using entity query an accessCheck() needs to be explicitly checked which was missing in the below method getEntityResults() of the class `class VoteResultStorage extends SqlContentEntityStorage implements VoteResultStorageInterface` in the module.

Hence to fix we need to add accessCheck(True) to the entity query in the method getEntityResults.

🐛 Bug report
Status

Closed: works as designed

Version

3.0

Component

Code

Created by

🇮🇳India tdnshah

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

Comments & Activities

Production build 0.71.5 2024