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

Created on 16 November 2023, 8 months ago

Problem/Motivation

Not currently able to install D10 site from config when synonyms is involved.

In Query.php line 141:
[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().                                                                                                                           
                                                                                                                                         

Exception trace:
  at /var/www/html/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php:141
 Drupal\Core\Entity\Query\Sql\Query->prepare() at /var/www/html/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php:80
 Drupal\Core\Entity\Query\Sql\Query->execute() at /var/www/html/web/modules/contrib/synonyms/modules/synonyms_search/src/SynonymsService/Behavior/SearchService.php:157

Also, this error appeared multiple times:

Unexpected error during import with operation create for synonyms.synonym.field.taxonomy_term.glossary.field_synonym: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck().

Steps to reproduce

For me this is happening during migration from Drupal 9 to Drupal 10 where attempts to install the site in a new test location with
drush si --existing-config fails. I saw similar errors when running drush edel, in the upgraded version of my site, hence my attempt to try it in a 'clean' install. I couldn't trace the problem back to synonyms at that time (the backtrace seemed to point to core, but I don't think that can be right), but this seems to be a common problem, so in that case, it may or may not have been related to Synonyms.

Proposed resolution

The same error comes up for many modules when searching. Adding $query->accessCheck(FALSE); before line 157 of SearchService.php seems to allow install, but the other error is still shown.

Adding the same line before any instance of $query->execute(); in all the following files, seems to have got rid of the error messages:
synonyms/modules/synonyms_search/src/SynonymsService/Behavior/SearchService.php
synonyms/modules/synonyms_search/synonyms_search.module
synonyms/modules/synonyms_views_argument_validator/src/Plugin/views/argument_validator/SynonymsEntity.php
synonyms/src/Plugin/Synonyms/Provider/BaseField.php
synonyms/src/Plugin/Synonyms/Provider/EntityReferenceField.php
synonyms/src/Plugin/Synonyms/Provider/Field.php
synonyms/src/SynonymsService/ProviderService.php

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

2.1

Component

Code

Created by

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

Comments & Activities

Production build 0.69.0 2024