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] Service names containing underscores not working after upgrading to 6.4.0 #52815

Closed
paullallier opened this issue Nov 30, 2023 · 7 comments

Comments

@paullallier
Copy link
Contributor

Symfony version(s) affected

6.4.0

Description

Sorry - I'm not sure if this is a bug or just a misconfiguration by me.

Upgrading from 6.3.x to 6.4.0, and autowiring Redis is suddenly throwing an error.

How to reproduce

I have this, which works in 6.3.9:

<?php

declare(strict_types=1);

namespace App\MessageHandler;

use App\Message\ClearUserAccessTokens;
use Redis;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
readonly class ClearUserAccessTokensHandler
{
    public function __construct(protected Redis $redis_valid_token)
    {
    }

When I upgrade to 6.4.0, I get this error:

!!  In DefinitionErrorExceptionPass.php line 51:
!!                                                                                 
!!    Cannot autowire service "App\MessageHandler\ClearUserAccessTokensHandler":   
!!    argument "$redis_valid_token" of method "__construct()" references class "R  
!!    edis" but no such service exists. Did you mean to target one of "redis_vali  
!!    d_token", "redis_refresh" instead?                          

Might this be a bug, or just a config issue on my project (nothing changes apart from upgrading Symfony and a few other packages not related to Redis)

In case it's relevant, I'm using snc/redis-bundle to manage the services, with phpredis:

services:
    Redis $redis_valid_token: '@snc_redis.valid_token'
    Redis $redis_refresh: '@snc_redis.refresh'


snc_redis:
    clients:
        refresh:
            type: phpredis
            alias: refresh
            dsn: "%env(REDIS_URL_REFRESH)%"
        valid_token:
            type: phpredis
            alias: valid_token
            dsn: "%env(REDIS_URL_VALIDTOKEN)%"

If I rollback the upgrade, it starts working again.

Possible Solution

No response

Additional Context

No response

@derrabus
Copy link
Member

Please provide a reproducer for your bug.

@HypeMC
Copy link
Contributor

HypeMC commented Nov 30, 2023

Seems to be related to #50718

@aboks
Copy link
Contributor

aboks commented Nov 30, 2023

Small reproduction script for this issue:

<?php
// Install symfony/dependency-injection (6.3 works ok, 6.4 fails)

use Symfony\Component\DependencyInjection\ContainerBuilder;

require_once __DIR__ . "/vendor/autoload.php";

class MyClass {
	public function __construct(\DateTimeImmutable $now_datetime) {}
}

$container = new ContainerBuilder();
$container->autowire(\DateTimeImmutable::class . ' $now_datetime', \DateTimeImmutable::class);
$container->autowire(MyClass::class, MyClass::class)->setPublic(true);
$container->compile();

$container->get(MyClass::class);

print "OK";

The essence is that the argument name (here: $now_datetime) contains an underscore. A name without an underscore works fine. Possibly there are other characters that introduce the same problem.

@derrabus
Copy link
Member

derrabus commented Nov 30, 2023

Thanks. I've run git bisect on that reproducer and found 8d60a7e as the first commit on which it fails. That's indeed #50718 by @nicolas-grekas.

@paullallier
Copy link
Contributor Author

Thank you for digging / the reproducer - I suspect it would have taken me quite a while...

@paullallier paullallier changed the title [Autowiring] Redis class not found after upgrading to 6.4.0 [DependencyInjection] Redis class not found after upgrading to 6.4.0 Nov 30, 2023
@paullallier paullallier changed the title [DependencyInjection] Redis class not found after upgrading to 6.4.0 [DependencyInjection] Service names containing underscores not working after upgrading to 6.4.0 Nov 30, 2023
@nicolas-grekas
Copy link
Member

This should be fixed by #52836.
Please confirm if you can.

@paullallier
Copy link
Contributor Author

Works for me - all my tests pass. Thanks!

nicolas-grekas added a commit that referenced this issue Dec 1, 2023
… that contain underscores (nicolas-grekas)

This PR was merged into the 6.4 branch.

Discussion
----------

[DependencyInjection] Fix parsing named autowiring aliases that contain underscores

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #52815
| License       | MIT

Fixing a regression introduced in #50718

Commits
-------

69a115c [DependencyInjection] Fix parsing named autowiring aliases that contain underscores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants