Change record status: 
Project: 
Introduced in branch: 
11.5.x
Introduced in version: 
Description: 

See this CR for more information about queries carrying cacheable metadata: https://www.drupal.org/node/3533258

From now on, if a query has cacheable metadata and no RefinableCacheableDependencyInterface is passed into its execute() method, a deprecation error will be triggered. From Drupal DECIDE_VERSION_NUMBER onward, an exception will be thrown instead.

Before:

$storage = $this->entityTypeManager->getStorage($entity_type_id);
$recent_entity_ids = $storage->getQuery()
  ->accessCheck(TRUE)
  ->sort($entity_type->getKey('id'), 'DESC')
  ->pager(10)
  ->execute(); // Will trigger deprecation error if query tags caused cacheable metadata to be added.

After:

$storage = $this->entityTypeManager->getStorage($entity_type_id);
$cacheability = new CacheableMetadata();
$recent_entity_ids = $storage->getQuery()
  ->accessCheck(TRUE)
  ->sort($entity_type->getKey('id'), 'DESC')
  ->pager(10)
  ->execute($cacheability);
$cacheability->applyTo($form);

In a later update, we will start triggering the deprecation notice when you are not capturing the possible metadata, rather than the actual metadata. I.e.: When a query is tagged, even if it does not contain any cacheable metadata during the current request.

Impacts: 
Module developers