Problem/Motivation

Caching is disabled on the REST resource because an object not implementing the CacheableDependencyInterface is passed to addCacheableDependency. In fact, the object being passed is currently an array.

------ --------------------------------------------------------------------- 
  Line   src/Plugin/rest/resource/VertexAISearchResource.php                  
 ------ --------------------------------------------------------------------- 
  150    Calling addCacheableDependency($object) when $object does not        
         implement CacheableDependencyInterface effectively disables caching  
         and should be avoided.                                               
         🪪  cacheable.dependency   

Steps to reproduce

This issue is being found by phpstan in the pipelines for any MRs.

Proposed resolution

Create a CacheableMetadata object and add the url.query_args context to it.
Pass this to the resourceResponse cacheable dependency.

    // Create a cacheable metadata object.
    $cacheMetadata = new CacheableMetadata();

    // Add the query arguments context so variations cache correctly.
    $cacheMetadata->addCacheContexts(['url.query_args']);
  
    $resourceResponse->addCacheableDependency($cacheMetadata);
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

timozura created an issue. See original summary.

timozura’s picture

Issue summary: View changes

timozura’s picture

Status: Active » Fixed

Needed to fix as it was preventing clean pipeline runs for additional MRs.
Fix added, merged into dev.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.