Drupal - LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected

Modify your entity query to something like below

$entities = \Drupal::entityQuery('node')
            ->condition('status', 1)
            ->condition('type', 'article')
            ->condition('langcode','en')
            ->notExists('field_f1')
            ->sort('created', 'DESC')
            ->range(0, 20)
            ->accessCheck(false)   
            ->execute();

I have solved it by adding code at the end because class ResourceResponse is using CacheableResponseTrait which is responsible to cache metadata. In POST, PATCH, DELETE we don't want that because resources are modified.

return new ModifiedResourceResponse($node);

https://tutel.me/c/drupal/questions/249627/logicexception+node+save+via+resourcebase+post#


I think the answers that are currently listed are the proper methods to follow. However, I think its relevant to note, that I was able to fix this (possibly temporarily) by reinstalling the jsonapi module in drupal using composer. In case it may help someone, this is what I ran from the command line:

composer require 'drupal/jsonapi:^1.24'

Don't forget to change the code to the version you are trying to install. As you can see, this is specifically for version 1.24.