symfony: Annotation @required causing issue after migrating from 6.0 to 6.1
Symfony version(s) affected
6.1.0
Description
Hello,
I just tried to migrate my Symfony 6.0 to 6.1 and since then I have the following issue:
[Semantical Error] The annotation "@Symfony\Contracts\Service\Attribute\Required" in method Symfony\Bundle\FrameworkBundle\Controller\AbstractController::setContainer() was never imported. Did you maybe forget to add a "use" statement for this annotation?
When I remove “@required” annotation from AbstractController.php file if works properly.
Any ideas on why I have this error suddently raised?
How to reproduce
I’m not sure on how to provide a reproducer…
Possible Solution
No response
Additional Context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 25 (18 by maintainers)
Commits related to this issue
- feature #48810 Drop v1 contracts packages everywhere (derrabus) This PR was merged into the 6.3 branch. Discussion ---------- Drop v1 contracts packages everywhere | Q | A | ----------... — committed to symfony/symfony by chalasr 2 years ago
- bug #48874 [FrameworkBundle] remove double required annotation + attribute (alexislefebvre) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] remove double required an... — committed to symfony/framework-bundle by fabpot a year ago
- bug #48916 [FrameworkBundle] restore call to addGlobalIgnoredName (alexislefebvre) This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] restore call to addGlobalIgnoredNa... — committed to symfony/symfony by nicolas-grekas a year ago
- bug #48874 [FrameworkBundle] remove double required annotation + attribute (alexislefebvre) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] remove double required an... — committed to symfony/framework-bundle by fabpot a year ago
The reproducer also experiences the bug with
symfony/service-contracts:^3.0, can this issue be reopened? Or is it fine to just continue with the PR only?I have been able to create a reproducer: https://github.com/alexislefebvre/symfony_bug_app_48792
Input:
Output:
Full exception trace when running <kbd>bin/console cache:warmup -vvv</kbd>
If we delete
src/Controller/DefaultController.phpthen it works again.@derrabus @nicolas-grekas I can confirm that updating symfony/service-contracts to 3 has fixed the issue. Thanks for you help.
I think this can be closed then.
When I run
symfony console debug:container annotations.reader --show-arguments, I can’t see theaddGlobalIgnoredNamemethod call in there, yet we do configure it: https://github.com/symfony/symfony/blob/6f755295892cba0ae84872221f93b6c582a88104/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php#L25-L29I tried to detect this bug on our projects. It only appears when doctrine/annotations is called and when doctrine’s mapping is specifying the annotations as type. Did you try to add them?
I hope it will help the error to pop, @alexislefebvre . Be careful with the cache. I manually delete the cache directly between each testsuite.
Please reopen the issue, the problem still exists with Symfony 6.2 (and maybe 6.0 and 6.1). It was closed from the merge because I referenced it but it has been merged on 6.3 only.
So, Doctrine Annotations is installed although you don’t use it at all? This is an issue that’s being worked on, see doctrine/DoctrineBundle#1598
All right. Please get back to us as soon as you have one. It helps others to track down the issue and work on a fix.