Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Description
Symfony version(s) affected
6.4.10
Description
The problem in short: DI removes doctrine repository, which is used in non-shared services, and throws an exception "You have requested a non-existent service "App\Repository\ChannelRepository"" under certain circumstances.
I stumbled upon this issue on working project, got rid of everything unrelated and tried to minimize the code. So, I have a Console command, which usesCheckEmail
service:
#[AsCommand('app:check-inbox','Check inbox and process emails')]class CheckInboxCommandextends Command{protectedCheckEmail$action;publicfunction__construct(CheckEmail$command ) {parent::__construct(); }}
CheckEmail
is a public non-shared service, which depends on two another services (processors):
<?phpnamespaceApp\Action;useApp\Processor;class CheckEmail{publicfunction__construct(\App\Processor\FirstProcessor$firstProcessor,\App\Processor\SecondProcessor$secondProcessor, ) { }}
And two similar processors, which uses serviceChannelRepository
:
<?phpnamespaceApp\Processor;useApp\Repository\ChannelRepository;usePsr\Log\LoggerInterface;class FirstProcessor{publicfunction__construct(LoggerInterface$logger,ChannelRepository$channelRepository, ) { }}
<?phpnamespaceApp\Processor;useApp\Repository\ChannelRepository;usePsr\Log\LoggerInterface;class SecondProcessor{publicfunction__construct(//LoggerInterface $logger,ChannelRepository$channelRepository, ) { }}
If I try to build container (clear cache or open/
in browser), I get error "You have requested a non-existent service "App\Repository\ChannelRepository"". But there are some changes (any of them), when everything starts working:
- If
App\Action\CheckEmail
is made shared (remove "shared: false" in services.yaml), the error dissappears. - If I comment
$logger
inFirstProcessor
constructorhttps://github.com/unnamed777/project_issue/blob/master/src/Processor/FirstProcessor.php#L10, the error disappears. - If I use
CheckEmail
in constructor of another service (and keep it in constructor ofCheckInboxCommand
), the error disappears. For instancehttps://github.com/unnamed777/project_issue/blob/master/src/Controller/DevController.php#L11, uncommenting$action
inDevController
resolves problem. - If I remove
CheckEmail
fromCheckInboxCommand
constructor and add it inDevController
constructor, the error disappears.
How to reproduce
PHP 8.1 is required
- Clonehttps://github.com/unnamed777/project_issue
symfony composer install
. You'll get the the same error, but it's ok for now.symfony serve
- Open link provided by Symfony CLI. The error is appeared.
- Open
src/Processor/FirstProcesssor.php
and comment line with$logger
in constructor. Refresh page, the error is gone. - Undo previous change. Open
src/Controller/DevController.php
and uncommend line 11 (CheckEmail $action
). The error is gone. - Try other actions from description part.
Possible Solution
No response
Additional Context
Comparison of a log ofSymfony\Component\DependencyInjection\Compiler
shows the difference only in one line (it exists when the problem is here):
Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass: Inlined service "App\Repository\ChannelRepository" to "App\Processor\FirstProcessor".