collections: V1.6.0 throws errors in Symfony context

Using API platform.

After the update to 1.6.0 cache:clear throws an error:

Script cache:clear returned with error code 1
!!  
!!   // Clearing the cache for the dev environment with debug                       
!!   // true                                                                        
!!  
!!  
!!  In FileLoader.php line 166:
!!                                                                                 
!!    [Semantical Error] The annotation "@template" in class Doctrine\Common\Coll  
!!    ections\Collection was never imported. Did you maybe forget to add a "use"   
!!    statement for this annotation? in . (which is being imported from "/srv/api  
!!    /config/routes/api_platform.yaml"). Make sure there is a loader supporting   
!!    the "api_platform" type.                                                     
!!                                                                                 
!!  
!!  In AnnotationException.php line 54:
!!                                                                                 
!!    [Semantical Error] The annotation "@template" in class Doctrine\Common\Coll  
!!    ections\Collection was never imported. Did you maybe forget to add a "use"   
!!    statement for this annotation?                                               
!!                                                                                 
!!  

config/routes/api_platform.yml

api_platform:
    resource: .
    type: api_platform

Origin: @template T in https://github.com/doctrine/collections/commit/7ddac104668249f0f4803b128eb30d0564467a68#diff-6ecd3b230c9f7cef1a38ea4da84278f3R27

After manually fixing doctrine/collection in composer.json to 1.5.0 it works again.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 18 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Handled and tested: preparing release.

As noted in https://github.com/doctrine/collections/pull/177#issuecomment-472467691, scavenging vendor/ for annotations is not a good idea. This is an issue to be reported in APIPlatform.

Well, multiple Symfony component needs to be able to read metadata (potentially using annotations) from arbitrary classes (Validator and Serializer are the one coming to my mind right now). And at least for these 2 components, it is very common to use them on object graphs involving Doctrine collections (as a common use case is to use them on your entities). Most of the time, you won’t need any metadata there, as you want to treat the collection with the standard handling of Traversable. But this does not mean that Symfony forbids defining a custom behavior, and so it still tries to find the metadata.

The fix for that would be to ignore the Psalm-specific tags in doctrine/annotations by default, as is done already for phpdoc tags.

Please note: you’ll need doctrine/collections 1.6.1 along with doctrine/annotations 1.6.1.

Yeah, currently patching doctrine/annotations, since - is not a valid class identifier anyway