-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Annotation @required causing issue after migrating from 6.0 to 6.1 #48792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some additional infos. If I change AbstractController::setContainer method from:
to:
I don't have the issue anymore. Here is the output for services for annotations: |
Which version of |
Please create a reproducer. |
@alamirault we are not using directly doctrine/annotations in composer.json. A bit the same setup as Symfony demo app (except that in this case the bug directly appears when going from 6.0 to 6.1). @derrabus I'll try to create a reproducer but it is not easy as I suspect we are in a similar situation than this one: #32347 (this is why I've posted my annotations.reader service). As a workaround for now I've put AbstractController in our src/App/Controller, removed the @required annotation and inheritated our controllers to this one. |
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. |
@derrabus it was finally simple to reproduce: https://github.com/jeanatpi/symfony_bug_48792 Checking out this repo and running composer install might generate the error Thanks for sharing the info on doctrine annotations. What I still don't get is the difference between my setup and the symfony demo app one. I continue investigating. |
It looks like the issue appears when adding doctrine/doctrine-bundle. What I don't get is why this issue is not appearing for symfony demo app. As package list is the similar: https://github.com/symfony/demo/blob/main/composer.json |
Is there a reason why you've pinned the service contracts to v1? Are you able to upgrade to v2 or v3? Can you confirm that the problem goes away if you do? |
This might be a doctrine/annotations issue. |
Yes, but it has never been legit to use an undefined class in a doc block analyzed by Doctrine Annotations. Doctrine Annotations does not care about the attribute, but it sees a Since #45680 this is a different story: The Since the issue is solved by bumping service contracts, my suggestion would be to make FrameworkBundle (or DI) conflict with ServiceContracts < 2.2. Maybe we should even do that for all contracts packages: Contracts v1 had been released during the Symfony 4 days, Contracts v2 were shipped with Symfony 5. |
I see thanks for the details.
This is the fix. Doing nothing on our side would be fine to me. |
@derrabus @nicolas-grekas I can confirm that updating symfony/service-contracts to 3 has fixed the issue. I think this can be closed then. |
No, but it would give people a nudge when upgrading to the next Symfony minor. I believe, there should not be a reason to operate a Symfony 6 app with a Contracts v1 package. I'll prepare a PR for 6.3, let's discuss this topic there. |
This PR was merged into the 6.3 branch. Discussion ---------- Drop v1 contracts packages everywhere | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Version 1 of the Symfony contracts have been released during the Symfony 4.x days, but still many Symfony 6 components declare compatibility with them: https://github.com/symfony/symfony/blob/a8bbf632df06b26bbd8a62f22203054bbff34d32/src/Symfony/Component/DependencyInjection/composer.json#L22 This circumstance complicates our build matrix and makes issues like #48792 hard to track down. Version 2 was released together with Symfony 5 which means that we really only need v1 contracts if we want to actively support Symfony 4 components which are EOL and already unsupported by Symfony 6. I make the bold assumption that no Symfony 6 app should be required to pin any of the contracts packages to v1 or even an outdated v2 minor release. This is why I propose to drop support for contracts v1 everywhere it did not happen already, making `^2.5 || ^3` the loosest constraint we use for a contracts package on a Symfony 6.3 component or bundle. Commits ------- 8671ad5 Drop v1 contracts packages everywhere
Hi, I had this problem today after installation of the last version of doctrine/annotations. |
Just a not that I also am having this problem with a Symfony 5.4 project and doctrine/annotations 2.0. I was able to "fix" it by changing my doctrine/annotations line in composer.json from "^2.0" to "^1.14" I also likely confirmed that somewhere in my project there is a configuration error, but it isn't clear where. Because I tried created a new symfony project and it doesn't have the problem, but my older project does. Still hunting for the culprit. |
I have the same issue with Symfony 6.2, upgrading to mildy long log
Here is the mentioned file: # config/routes.yaml
controllers:
resource: ../src/Controller/
type: attribute
app_logout:
path: /logout
methods: GET |
I have been able to create a reproducer: https://github.com/alexislefebvre/symfony_bug_app_48792 Input: git clone [email protected]:alexislefebvre/symfony_bug_app_48792.git
cd ./symfony_bug_app_48792/
composer install Output: Installing dependencies from lock file (including require-dev)
[…]
Run composer recipes at any time to see the status of your Symfony recipes.
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! // Clearing the cache for the dev environment with debug true
!!
!!
!! In FileLoader.php line 178:
!!
!! [Semantical Error] The class "Symfony\Contracts\Service\Attribute\Required"
!! is not annotated with @Annotation.
!! Are you sure this class can be used as annotation?
!! If so, then you need to add @Annotation to the _class_ doc comment of "Symf
!! ony\Contracts\Service\Attribute\Required".
!! If it is indeed no annotation, then you need to add @IgnoreAnnotation("requ
!! ired") to the _class_ doc comment of method Symfony\Bundle\FrameworkBundle\
!! Controller\AbstractController::setContainer() in {"path":"..\/src\/Controll
!! er\/","namespace":"App\\Controller"} (which is being imported from "/dev/sh
!! m/symfony_bug_app_48792/config/routes.yaml"). Make sure there is a loader s
!! upporting the "attribute" type.
!!
!!
!! In AnnotationException.php line 36:
!!
!! [Semantical Error] The class "Symfony\Contracts\Service\Attribute\Required"
!! is not annotated with @Annotation.
!! Are you sure this class can be used as annotation?
!! If so, then you need to add @Annotation to the _class_ doc comment of "Symf
!! ony\Contracts\Service\Attribute\Required".
!! If it is indeed no annotation, then you need to add @IgnoreAnnotation("requ
!! ired") to the _class_ doc comment of method Symfony\Bundle\FrameworkBundle\
!! Controller\AbstractController::setContainer().
!!
!!
!! cache:clear [--no-warmup] [--no-optional-warmers]
!!
!!
Script @auto-scripts was called via post-install-cmd Full exception trace when running bin/console cache:warmup -vvv
If we delete |
The reproducer also experiences the bug with |
…ibute (alexislefebvre) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] remove double required annotation + attribute | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48792 (checked with [this reproducer](symfony/symfony#48792 (comment))) | License | MIT | Doc PR | no Annotation and attribute were kept: symfony/symfony#45680 (comment) To my understanding, it's not necessary since #48810 Alternative to #48868 Commits ------- 8e8772d2c1 remove double required annotation + attribute
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. |
I tried to add a test in Symfony based on the reproducer but the error never pop. It must be a very different context than from a standalone Symfony app. |
I 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? orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotations # if you use annotations, the bug appears. If you attributes and (wrongly) specify annotations, the bug appears too. If I use attributes and specify attributes, bug disappears.
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App I hope it will help the error to pop, @alexislefebvre . Be careful with the cache. I manually delete the cache directly between each testsuite. |
@Alexandre-T thanks for testing, I tried your conf in a project and it doesn't work for me. Note that the reproducer doesn't use Doctrine ORM or annotations, it's only an empty controller. But this line is causing the error: https://github.com/alexislefebvre/symfony_bug_app_48792/blob/7b4419b0ff736d1e3d1c54e65a4b0bf7fc686c1b/config/routes.yaml#L5 Update: Symfony already use this config this fixtures, it should break with Symfony 6.2 and annotations 2:
You're right about the cache, the issue appears when running I did some testing and it looks like |
When I run symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.php Lines 25 to 29 in 6f75529
|
If we comment Alternatively, it works too if we comment all code relevant to This means that calling |
…exislefebvre) This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] restore call to addGlobalIgnoredName | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48792 and replace #48912 | License | MIT | Doc PR | no The service `annotations.dummy_registry` is unregistered with `doctrine/annotations` v2. This had the unexpected effect to break the call to `addGlobalIgnoredName` with `doctrine/annotations` v2 : #48792 (comment) By using `nullOnInvalid` instead of `ignoreOnInvalid`, the call to `addGlobalIgnoredName` is restored. These changes can be tested with this reproducer: https://github.com/alexislefebvre/symfony_bug_app_48792 Downgrading and upgrading `doctrine/annotations` become possible: ```bash composer require doctrine/annotations:^1.13.0 --with-all-dependencies composer require doctrine/annotations:^2.0 --with-all-dependencies ``` Thanks to `@derrabus`: #48912 (comment) Commits ------- e058874 [FrameworkBundle] restore call to addGlobalIgnoredName
…ibute (alexislefebvre) This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] remove double required annotation + attribute | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48792 (checked with [this reproducer](symfony/symfony#48792 (comment))) | License | MIT | Doc PR | no Annotation and attribute were kept: symfony/symfony#45680 (comment) To my understanding, it's not necessary since #48810 Alternative to #48868 Commits ------- 8e8772d2c1 remove double required annotation + attribute
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
The text was updated successfully, but these errors were encountered: