Access checking must be explicitly specified on content entity queries

Created on 20 April 2023, over 1 year ago
Updated 22 April 2023, over 1 year ago

Problem/Motivation

Drupal 10 throws an error when access check is not explicitly specified on content entity queries.
See: https://www.drupal.org/node/3201242

When adding a entity reference field to a node type in D10 this error is thrown:

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/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

The error occurs because in this query no access check is explicitly defined:
RadioactivityReferenceItem.php
$query = $entityStorage->getQuery()->count();

Steps to reproduce

Add a radioactivity reference field on a node type in Drupal 10.

Proposed resolution

Add

$query->accessCheck(TRUE);

on exisiting queries. The behavior will not be changing as this was a previous default.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

🇳🇱Netherlands thomasdegraaff

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

Comments & Activities

Production build 0.71.5 2024