{"action":"closed","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/27053","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/27053/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/27053/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/27053/events","html_url":"https://github.com/symfony/symfony/issues/27053","id":317758971,"number":27053,"title":"Running container is being deleted when dependency is autowired implicitly in Symfony 3","user":{"login":"ostrolucky","id":496233,"avatar_url":"https://avatars2.githubusercontent.com/u/496233?v=4","gravatar_id":"","url":"https://api.github.com/users/ostrolucky","html_url":"https://github.com/ostrolucky","followers_url":"https://api.github.com/users/ostrolucky/followers","following_url":"https://api.github.com/users/ostrolucky/following{/other_user}","gists_url":"https://api.github.com/users/ostrolucky/gists{/gist_id}","starred_url":"https://api.github.com/users/ostrolucky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ostrolucky/subscriptions","organizations_url":"https://api.github.com/users/ostrolucky/orgs","repos_url":"https://api.github.com/users/ostrolucky/repos","events_url":"https://api.github.com/users/ostrolucky/events{/privacy}","received_events_url":"https://api.github.com/users/ostrolucky/received_events","type":"User","site_admin":false},"labels":[{"id":100079,"url":"https://api.github.com/repos/symfony/symfony/labels/Bug","name":"Bug","color":"e10c02","default":false},{"id":99863,"url":"https://api.github.com/repos/symfony/symfony/labels/DependencyInjection","name":"DependencyInjection","color":"DDDDDD","default":false},{"id":237003792,"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-04-25T19:16:45Z","updated_at":"2018-04-26T15:06:28Z","closed_at":"2018-04-26T15:06:28Z","author_association":"CONTRIBUTOR","body":"| Q                | A\r\n| ---------------- | -----\r\n| Bug report?      | yes\r\n| Feature request? | no\r\n| BC Break report? | no\r\n| RFC?             | no\r\n| Symfony version  | 3.4\r\n\r\nI have changed constructor dependency from Doctrine's ApplicationRepository (which has service ID same as FCQN) into dependency which has ID not matching FCQN, configured with legacy style, like:\r\n```yaml\r\npanel.application.application_history:\r\n  class: AppBundle\\Panel\\Panels\\Application\\ApplicationHistory\r\n  arguments: [ '@manager.application', '@manager.user' ]\r\n```\r\n\r\n```php\r\nclass HistoryWindowController extends Controller\r\n{\r\n    private $applicationHistoryPanel;\r\n\r\n    public function __construct(ApplicationHistory $applicationHistoryPanel)\r\n    {\r\n        $this->applicationHistoryPanel = $applicationHistoryPanel;\r\n    }\r\n\r\n    public function __invoke(Application $application)\r\n    {\r\n        ...\r\n    }\r\n}\r\n\r\n```\r\n\r\nIt works. BUT\r\n\r\n\r\nAfter doing that, tests started to blow up with messages like:\r\n\r\n```\r\nSymfony\\Component\\Debug\\Exception\\FatalErrorException:\r\nCompile Error: ContainerX6wnwgd\\appTestDebugProjectContainer::load(): Failed opening required '/var/www/var/cache/test/ContainerX6wnwgd/getJmsJobQueue_Entity_ManyToAnyListenerService.php' (include_path='.:/usr/local/lib/php')\r\n\r\n  at var/cache/test/ContainerX6wnwgd/appTestDebugProjectContainer.php:2481\r\n  at ContainerX6wnwgd\\appTestDebugProjectContainer->load('file' => '???', 'lazyLoad' => '???')\r\n     (vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:304)\r\n  at ContainerX6wnwgd\\appTestDebugProjectContainer->get('id' => '???', 'invalidBehavior' => '???')\r\n     (vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php:58)\r\n  at Symfony\\Bridge\\Doctrine\\ContainerAwareEventManager->dispatchEvent('eventName' => '???', 'eventArgs' => '???')\r\n     (vendor/doctrine/orm/lib/Doctrine/ORM/Event/ListenersInvoker.php:117)\r\n  at Doctrine\\ORM\\Event\\ListenersInvoker->invoke('metadata' => '???', 'eventName' => '???', 'entity' => '???', 'event' => '???', 'invoke' => '???')\r\n     (vendor/doctrine/orm/lib/Doctrine/ORM/Internal/HydrationCompleteHandler.php:99)\r\n```\r\n\r\nTest looks like this:\r\n\r\n```php\r\n$client = static::createClient();\r\n\r\n$oppManager = $container->get('manager.opportunity');\r\n\r\n$this->assertSomething($client->request(...));\r\n$this->assertSomething($client->request(...));\r\n$this->assertSomething($client->request(...));\r\n\r\n$oppManager->findOneBy([])->getId(); // here it blows up\r\n```\r\n\r\nWhat I found is that after each $client->request(), container is being replaced, so when it comes to executing `$oppManager->findOneBy()`, old container folder does no longer exist, so classes which weren't loaded yet at that point, cannot.\r\n\r\nI also tried to find out why is container being regenerated and what I found is that resource is marked as ClassExistenceResource for `EntityManager5ae0c6b8bc55b_546a8d27f194334ee012bfe64f629947b07e4919\\__CG__\\Doctrine\\ORM\\EntityManager`. Such key has `false` value in `\\Symfony\\Component\\Config\\Resource\\ClassExistenceResource#existsCache[1]`. Variable $exists is true and $this->exists is false. This results in false return.\r\n\r\nThis issue has been discovered in Symfony 3.4.4. I updated and is still present in Symfony 3.4.8.\r\n\r\nIssue is resolved when I alias the service so FCQN matches ID:\r\n```yaml\r\nAppBundle\\Panel\\Panels\\Application\\ApplicationHistory: '@panel.application.application_history'\r\n```\r\n\r\nHere are some other things which might help:\r\n- Controller is in AppBundle, but test is in ApiBundle (and doesn't test that controller).\r\n- AppBundle tests don't have this issue, only ApiBundle ones\r\n\r\nI realize these autowiring fallbacks are deprecated, but it shouldn't blow up like this and will make it hard to migrate"}}
{"actor":{"display_login":"nicolas-grekas"}}