Problem/Motivation

After installing the GDPR Consent module and attempting to add a Consent field to a User entity, I encounter the following 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 core/lib/Drupal/Core/Entity/Query/Sql/Query.php).

This occurs when trying to complete the final step of the field addition process.

Proposed resolution

The solution is to add an explicit access check to the entity query in the UserConsentItem.php file. Here is the modified code:

$agreement_ids = \Drupal::entityQuery('gdpr_consent_agreement')
  ->condition('status', 1)
  ->accessCheck(TRUE)
  ->sort('title')
  ->execute();

$agreements = ConsentAgreement::loadMultiple($agreement_ids);

I've attached a patch with this change.

Steps to reproduce

Install the GDPR Consent module.
Try to add a Consent field to the User entity.
Follow the steps to add a field.
At the last step, the error appears.

CommentFileSizeAuthor
#2 accessCheckFix.patch570 bytesrbosscher

Issue fork gdpr-3373447

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rbosscher created an issue. See original summary.

rbosscher’s picture

StatusFileSize
new570 bytes
keshavv’s picture

Status: Active » Needs review
silvi.addweb’s picture

Status: Needs review » Reviewed & tested by the community

When I added the Consent field, I ran into this problem.

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

.

After adding this patch it's working fine.

Rajeshreeputra made their first commit to this issue’s fork.

  • Rajeshreeputra committed 50df2a97 on 3.0.x
    Issue #3373447 by Rajeshreeputra, rbosscher, keshavv, silvi.addweb:...
rajeshreeputra’s picture

Status: Reviewed & tested by the community » Fixed

Merged!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.