Skip to content
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

[DependencyInjection] Can not replace arguments if none have been configured yet - InlineAutowire #54823

Closed
soyuka opened this issue May 2, 2024 · 5 comments · Fixed by #54908

Comments

@soyuka
Copy link
Contributor

soyuka commented May 2, 2024

Symfony version(s) affected

7.1

Description

Cache clear drops:

  [Symfony\Component\DependencyInjection\Exception\OutOfBoundsException]
  Service "ApiPlatform\Tests\Behat\DoctrineContext": Cannot replace arguments for class "ApiPlatform\Tests\Behat\DoctrineContext" if none have been configured yet.

Exception trace:
  at /symfony/dependency-injection/Definition.php:257
 Symfony\Component\DependencyInjection\Definition->replaceArgument() at /symfony/dependency-injection/Compiler/ResolveChildDefinitionsPass.php:167
 Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass->doResolveDefinition() at /symfony/dependency-injection/Compiler/ResolveChildDefinitionsPass.php:63
 Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass->resolveDefinition() at /symfony/dependency-injection/Compiler/ResolveChildDefinitionsPass.php:46
 Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass->processValue() at /symfony/dependency-injection/Compiler/AbstractRecursivePass.php:84
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /symfony/dependency-injection/Compiler/ResolveChildDefinitionsPass.php:37
 Symfony\Component\DependencyInjection\Compiler\ResolveChildDefinitionsPass->processValue() at /symfony/dependency-injection/Compiler/AbstractRecursivePass.php:45
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /symfony/dependency-injection/Compiler/Compiler.php:73
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /symfony/dependency-injection/ContainerBuilder.php:752
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /symfony/http-kernel/Kernel.php:495
 Symfony\Component\HttpKernel\Kernel->initializeContainer() at /symfony/http-kernel/Kernel.php:732
 Symfony\Component\HttpKernel\Kernel->preBoot() at /symfony/http-kernel/Kernel.php:120
 Symfony\Component\HttpKernel\Kernel->boot() at /symfony/http-kernel/Kernel.php:135
 Symfony\Component\HttpKernel\Kernel->reboot() at /symfony/framework-bundle/Command/CacheClearCommand.php:229
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->warmup() at /symfony/framework-bundle/Command/CacheClearCommand.php:141
 Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand->execute() at /symfony/console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at /symfony/console/Application.php:1047
 Symfony\Component\Console\Application->doRunCommand() at /symfony/framework-bundle/Console/Application.php:123
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /symfony/console/Application.php:316
 Symfony\Component\Console\Application->doRun() at /symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /symfony/console/Application.php:167
 Symfony\Component\Console\Application->run() at tests/Fixtures/app/console:36

cache:clear [--no-warmup] [--no-optional-warmers]

How to reproduce

git clone git@github.com:api-platform/core
composer config minimum-stability dev
php -d memory_limit=-1 tests/Fixtures/app/console cache:clear --ansi

But actually the service declaration is as simple as:

services:
    _defaults:
        public: false
        autowire: true
        autoconfigure: true

    ApiPlatform\Tests\Behat\DoctrineContext:
        $doctrine: '@doctrine'

Possible Solution

I tracked the bug to:

if ($arguments !== $value->getArguments()) {
$value->setArguments($arguments);
}

Probably that this pass should be done later on? Not sure what AutowireInline actually tries to fix.

If I may also the code change at b9a838e#diff-a0f563695b61a31b6e2bee8d55d019b52326c245667db02ba878a2a878d78b98 should be commented as it's hard to know why the sudden change of testing for . as first char of the service name

Additional Context

No response

@derrabus
Copy link
Member

derrabus commented May 2, 2024

This bug can be observed when using the #[WithMonologChannel] attribute on a service where some constructor arguments have been specified by name. edit: see my next comment.

Reproducer: https://github.com/derrabus/di-replace-arg-reproducer

The app on that reproducer repository works fine if you remove the last commit which upgrades from Symfony 7.0 to 7.1.

Status: Reviewed

@derrabus
Copy link
Member

derrabus commented May 2, 2024

This bug can be observed when using the #[WithMonologChannel] attribute on a service where some constructor arguments have been specified by name.

Update: It has nothing to do with the Monolog channel magic: A simple service that mixes autowiring with explicitly set named arguments is apparently enough. I've updated the reproducer.

@derrabus
Copy link
Member

derrabus commented May 2, 2024

git bisect says:

b9a838e is the first bad commit

ref #52820
cc @nicolas-grekas

@nicolas-grekas
Copy link
Member

Should be fixed by #54908

@soyuka
Copy link
Contributor Author

soyuka commented May 24, 2024

can confirm thanks @nicolas-grekas !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants