Entity queries must explicitly set whether the query should be access checked or not.

Created on 26 September 2023, about 1 year ago
Updated 23 January 2024, 11 months ago

Problem/Motivation

Installed latest release candidate with composer on a D10 site. enabled the redhen and contacts and immediately get the following exception.

The website encountered an unexpected error. Please try again later.

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).
Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 268)
Drupal\redhen_contact\Entity\Contact::loadByUser(Object) (Line: 748)
redhen_contact_user_format_name_alter('admin', Object, NULL) (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('user_format_name', 'admin', Object) (Line: 183)
Drupal\Core\Session\UserSession->getDisplayName() (Line: 163)
Drupal\Core\Session\AccountProxy->getDisplayName() (Line: 1155)
user_toolbar()
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'user') (Line: 388)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('toolbar', Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler->invokeAll('toolbar') (Line: 78)
Drupal\toolbar\Element\Toolbar::preRenderToolbar(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725 ', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 797)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 386)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 458)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 474)
Drupal\Core\Template\TwigExtension->escapeFilter(Object, Array, 'html', NULL, 1) (Line: 82)
__TwigTemplate_635254c7d26d15fb42ff21b843759ae8->doDisplay(Array, Array) (Line: 394)
Twig\Template->displayWithErrorHandling(Array, Array) (Line: 367)
Twig\Template->display(Array) (Line: 379)
Twig\Template->render(Array, Array) (Line: 40)
Twig\TemplateWrapper->render(Array) (Line: 53)
twig_render_template('core/themes/claro/templates/classy/layout/html.html.twig', Array) (Line: 372)
Drupal\Core\Theme\ThemeManager->render('html', Array) (Line: 445)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array) (Line: 158)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 159)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 187)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: duplicate

Version

2.0

Component

Shared

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @mike vogel
  • As shown below, I added accessCheck(FALSE) line to the loadByUser function that threw the exception, uninstalled and reinstalled the modules and the problem didn't happen. I then turned on organizations and connections and got the fatal exception shown after the code.

    public static function loadByUser($account, $status = TRUE) {
    $contact = &drupal_static(__FUNCTION__ . $account->id(), FALSE);

    // If we don't have a cached Contact and we have a uid to load the Contact
    // by, proceed.
    if (!$contact && !empty($account->id())) {

    // Find Contacts linked to the current Drupal User.
    $query = \Drupal::entityQuery('redhen_contact');
    $query->accessCheck(FALSE);
    $query->condition('uid', $account->id(), '=');
    $query->condition('status', $status);
    $results = $query->execute();

    Fatal error: Declaration of Drupal\redhen_connection\Routing\RouteSubscriber::getSubscribedEvents() must be compatible with Drupal\Core\Routing\RouteSubscriberBase::getSubscribedEvents(): array in /var/www/html/web/modules/contrib/redhen/modules/redhen_connection/src/Routing/RouteSubscriber.php on line 66

  • Assigned to sarwan_verma
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sarwan_verma

    Hi mike vogel@,
    I have solve this issue and also created MR for this Drupal\Core\Entity\Query\QueryInterface::accessCheck() . Kindly review the changes .

    Thank you.

  • I reviewed and the MR looks correct and those changes fix the errors on my site. I

  • Status changed to Needs work about 1 year ago
  • As I've continued to use the site there are additional places where ->accessCheck(FALSE); is missing and I believe needs to be added. I only hit the bug in one of these places but I believe its needed in them all.

    - validate function in: redhen/modules/redhen_dedupe/src/Form/RedhenDedupeMergeForm.php
    - redhenDedupeMerge function in: redhen/modules/redhen_dedupe/src/Form/RedhenDedupeMergeForm.php
    - buildConfigurationForm function in: redhen/modules/redhen_connection/src/Plugin/Action/ChangeConnectionRole.php
    - loadByMail function in: web/modules/contrib/redhen/modules/redhen_contact/src/Entity/Contact.php

    After fixing those I encountered this error after creating an organization:

    The website encountered an unexpected error. Please try again later.

    TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string, Drupal\Core\Link given in htmlspecialchars() (line 436 of core/lib/Drupal/Component/Utility/Html.php).
    Drupal\Component\Utility\Html::escape(Object) (Line: 265)
    Drupal\Component\Render\FormattableMarkup::placeholderEscape(Object) (Line: 216)
    Drupal\Component\Render\FormattableMarkup::placeholderFormat('You have not created any %bundle types yet. @link to add a new type.', Array) (Line: 195)
    Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
    Drupal\Core\StringTranslation\TranslatableMarkup->__toString() (Line: 471)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 592)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 187)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    I think the fix is to apply the patch at: https://www.drupal.org/project/drupal/issues/3352384 Add Exception for TypeError Argument must be String in \Drupal\Component\Utility\Html escape{} Needs work but I haven't successfully done it yet.

  • Status changed to Closed: duplicate 11 months ago
  • 🇺🇸United States wxactly

    Marking this as a duplicate. Anyone following this issue should check out the patches here: https://www.drupal.org/project/redhen/issues/3402288#comment-15344955 🐛 Entity queries must explicitly set whether the query should be access checked or not RTBC

Production build 0.71.5 2024