Relying on entity queries to check access by default is deprecated in drupal:9.2.0.

Created on 15 March 2023, over 1 year ago
Updated 3 August 2023, about 1 year ago

Problem/Motivation

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.

📌 Task
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇮🇳India libbna New Delhi, India

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

Comments & Activities

  • Issue created by @libbna
  • Assigned to libbna
  • 🇮🇳India libbna New Delhi, India
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India libbna New Delhi, India
  • I'm on 10.1.2. Patch removes error. Thanks!

  • Status changed to Closed: works as designed about 1 year ago
  • 🇺🇸United States tr Cascadia

    This code appears in an update hook.

    Update hooks should not be changed, for many reasons but primarily because if two different sites are updated using different code in the "same" update hook, then we have no way of ensuring that those two sites end up in the state, and if there is a problem with one of the hooks we have no way to tell which sites ran the problem hook and which sites didn't. It is ALWAYS better to create a new update hook to fix any problems in a previous update hook, rather than to re-write a previous update hook.

    It is entirely valid for update hooks to contain code that is deprecated or even invalid in the latest version of Drupal core, because update hooks are used to update the contributed module between specific versions. Update hooks will never be run on new installs of the contributed module.

    In this case, the update hook in question was committed back in 2020, three years ago, before Drupal 9.2 existed, and a year before the usage in this hook was deprecated. When updating a site to a new version of Drupal the process is:
    1) First update the contributed modules to their most recent version.
    2) Update core.
    If the site upgrade is done properly, the update hooks will be run before core is updated, which means that things that are deprecated in the new version of core STILL WORK when the update hooks are run.

    While it is not technically wrong to add the accessCheck() to the update hook after the fact, I would rather the update hook fail because this update hook should NEVER run under Drupal 10. If it does run, then you have a problem on your site and this will stop you from proceeding further rather than working and letting you dig a bigger hole for yourself.

    BTW, I changed the status to "Task" because, as a deprecation introduced AFTER this module's code was written, it is not a "Bug", it is simply something that might need to be addressed eventually in the future. Nothing is broken by a deprecation, everything still works until the next major release. And deprecations are routine matters, not "Major".

Production build 0.71.5 2024