Deprecation notice Relying on entity queries to check access by default is deprecated

Created on 29 June 2022, almost 3 years ago
Updated 31 July 2023, over 1 year ago

Problem/Motivation

As of the current Drupal core (9.3.x), executing an entity query without a prior explicit call to ::accessCheck() is deprecated (originally it was not deprecated and accessCheck(TRUE) was implied in such a case).

It generates a deprecation like the following:
Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked. See https://www.drupal.org/node/3201242 →

Steps to reproduce

Invoking the ./tests/src/Functional/DecoupledRouterFunctionalTest.php will trigger the mentioned deprecation:

$ ../../vendor/bin/phpunit ../modules/contrib/decoupled_router/tests/src/Functional/DecoupledRouterFunctionalTest.php 
HTML output directory web/sites/simpletest/browser_output is not a writable directory.
PHPUnit 9.5.20 #StandWithUkraine

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing Drupal\Tests\decoupled_router\Functional\DecoupledRouterFunctionalTest
...                                                                 3 / 3 (100%)

Time: 00:21.938, Memory: 16.00 MB

OK (3 tests, 52 assertions)

Remaining self deprecation notices (37)

........

  7x: Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked. See https://www.drupal.org/node/3201242
    3x in DecoupledRouterFunctionalTest::testNegotiationNoMultilingual from Drupal\Tests\decoupled_router\Functional
    2x in DecoupledRouterFunctionalTest::testUnpublishedContent from Drupal\Tests\decoupled_router\Functional
    2x in DecoupledRouterFunctionalTest::testHomPathCheck from Drupal\Tests\decoupled_router\Functional

.......

Proposed resolution

Invoke ::accessCheck(TRUE) in the explicit way so the deprecation is not triggered.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇺🇦Ukraine bucefal91

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024