api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.4k stars 859 forks source link

Cache: TagCollector is not called when collection is empty #6546

Open TonySma opened 2 weeks ago

TonySma commented 2 weeks ago

API Platform version(s) affected: 3.3.11

Thanks to the new mechanism TagCollector, we move our custom logic to gather tags within a class implementing the interface, removing our decorations of deprecated api_platform.http_cache.listener.response.add_tags

Description
When a collection is empty, the TagCollectorInterface::collect() method is not called, so we just get the tags by default and can't add some by our own logic.

How to reproduce
Just create a class that implement the TagCollectorInterface and call a collection api with no results

Possible Solution
Looking into it now

Additional Context
The TagCollector interface is used in the AbstractItemNormalizer::normalize() method but the supports() is not validated because there is no data (and this is logic btw)

soyuka commented 2 weeks ago

@usu wdyt? could you provide a fix targetting 3.3 @TonySma ?

TonySma commented 2 weeks ago

Yep I will try Iris are collected in the AddTagsProcessor, if we add logic here, i'm not sure we can use the same interface ? The context seems not to be the same here

Do you have some insight / advice to achieve this ?