Fatal Php Error: Entity queries must explicitly set whether the query should be access checked or not

Created on 21 March 2024, 9 months ago

Problem/Motivation

When attemping to save a Salesforce Mapping a fatal error is thrown due to the UniqueFieldsConstraintValidator. There is a problem with the lack of an explicit access check for some reason. This may be related to a different upstream error but I have not found it.

The website encountered an unexpected error. 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).

Steps to reproduce

Attempt to update and save a Salesforce Mapping using the interface at /admin/content/salesforce

Proposed resolution

Either the Entity Query needs to have an explicity access check or there's an upstream bug in Drupal Core. I'm not sure.

Remaining tasks

User interface changes

API changes

Data model changes

๐Ÿ› Bug report
Status

Closed: cannot reproduce

Version

5.0

Component

salesforce_mapping.module

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States brooke_heaton

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

Merge Requests

Comments & Activities

  • Issue created by @brooke_heaton
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States brooke_heaton
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia dineshkumarbollu

    +1 for the issue

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia rakesh.regar Rajasthan, India

    rakesh.regar โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Raveen Kumar

    Yes, in recent drupal versions, Entity queries must explicitly set whether the query should be access checked or not.

    Here is an example of an entity query with access checking disabled.
    $query = \Drupal::entityQuery('node')
    ->condition('status', 1)
    ->accessCheck(FALSE) // Disable access checking
    ->execute();

  • Merge request !743432569-fatal-php-error-resolved โ†’ (Open) created by Unnamed author
  • Status changed to Needs review 9 months ago
  • Status changed to Closed: cannot reproduce 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States AaronBauman Philadelphia

    The access check is performed upon the query itself in \Drupal\salesforce_mapping\SalesforceMappingStorage::loadByProperties

      /**
       * {@inheritdoc}
       */
      public function loadByProperties(array $values = []) {
        // Build a query to fetch the entity IDs.
        $entity_query = $this->getQuery()->accessCheck(FALSE);
        $this->buildPropertyQuery($entity_query, $values);
        // Sort by the mapping weight to ensure entities/objects are processed in
        // the correct order.
        $entity_query->sort('weight');
        $result = $entity_query->execute();
        return $result ? $this->loadMultiple($result) : [];
      }
    

    SalesforceMappingStorage is just a wrapper.

    If you're still having this issue, can you please share a full stack trace?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States brooke_heaton

    Here is a full stack trace of my error, if this can help elucidate the problem. Sorry for any confusion:

    Backtrace	
    #0 /code/web/core/lib/Drupal/Core/Entity/Query/Sql/Query.php(80): Drupal\Core\Entity\Query\Sql\Query->prepare()
    #1 /code/web/modules/contrib/salesforce/modules/salesforce_mapping/src/Plugin/Validation/Constraint/UniqueFieldsConstraintValidator.php(37): Drupal\Core\Entity\Query\Sql\Query->execute()
    #2 /code/web/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(202): Drupal\salesforce_mapping\Plugin\Validation\Constraint\UniqueFieldsConstraintValidator->validate(Object(Drupal\salesforce_mapping\Entity\MappedObject), Object(Drupal\salesforce_mapping\Plugin\Validation\Constraint\MappingSfidConstraint))
    #3 /code/web/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(154): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object(Drupal\salesforce_mapping\Entity\MappedObject), '000000000000212...', Array)
    #4 /code/web/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(106): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter), Array, true)
    #5 /code/web/core/lib/Drupal/Core/TypedData/Validation/RecursiveValidator.php(93): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter), NULL, NULL)
    #6 /code/web/core/lib/Drupal/Core/TypedData/TypedData.php(132): Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object(Drupal\Core\Entity\Plugin\DataType\EntityAdapter))
    #7 /code/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(518): Drupal\Core\TypedData\TypedData->validate()
    #8 /code/web/core/lib/Drupal/Core/Entity/ContentEntityForm.php(188): Drupal\Core\Entity\ContentEntityBase->validate()
    #9 [internal function]: Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object(Drupal\Core\Form\FormState))
    #10 /code/web/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array(Array, Array)
    #11 /code/web/core/lib/Drupal/Core/Form/FormValidator.php(275): Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object(Drupal\Core\Form\FormState))
    #12 /code/web/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'salesforce_mapp...')
    #13 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormValidator->validateForm('salesforce_mapp...', Array, Object(Drupal\Core\Form\FormState))
    #14 /code/web/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm('salesforce_mapp...', Array, Object(Drupal\Core\Form\FormState))
    #15 /code/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\salesforce_mapping_ui\Form\MappedObjectForm), Object(Drupal\Core\Form\FormState))
    #16 /code/web/core/modules/layout_builder/src/Controller/LayoutBuilderHtmlEntityFormController.php(39): Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #17 [internal function]: Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
    #18 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #19 /code/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #20 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #21 /code/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #22 /code/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #23 /code/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #24 /code/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /code/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /code/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /code/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /code/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /code/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /code/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /code/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #33 /code/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #34 /code/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #35 {main}
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States AaronBauman Philadelphia

    Best I can tell, looks like you're on an old version.
    The line numbers don't match up with 5.0.4 or 5.0.x, and this was fixed in 5.0.3

    The issue with UniqueFieldsConstraintValidator was addressed here:
    ๐Ÿ› Entity queries must explicitly set whether the query should be access checked or not Fixed
    and here: https://git.drupalcode.org/project/salesforce/-/commit/48bcdc174373ec082...

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States brooke_heaton

    Oh interesting. Thanks for pointing that out. I'll look into it. Thanks Aaron!

Production build 0.71.5 2024