8000 [DI] [BC] Building service locator with non-shared services fails · Issue #27360 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] [BC] Building service locator with non-shared services fails #27360

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

Closed
curry684 opened this issue May 23, 2018 · 9 comments
Closed

[DI] [BC] Building service locator with non-shared services fails #27360

curry684 opened this issue May 23, 2018 · 9 comments

Comments

@curry684
Copy link
Contributor
curry684 commented May 23, 2018

Symfony version(s) affected: 4.1.0-beta2

Description
See https://travis-ci.org/omines/datatables-bundle/builds/382768680, build is failing only on 'dev', which is Symfony master branch. Following error occurs only in this build config:

PHP Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Invalid ignore-on-uninitialized reference found in service ".2_ServiceLocator~i_rgpvA": target service "Omines\DataTablesBundle\Adapter\ArrayAdapter" is not shared. in /home/travis/build/omines/datatables-bundle/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php:35

Same error also occurs when running tests in a real application with 4.1.0-beta2, but strangely not in its dev environment.

How to reproduce

git clone git@github.com:omines/datatables-bundle.git reproducer
cd reproducer
composer config minimum-stability dev
composer update
vendor/bin/phpunit
@curry684
Copy link
Contributor Author

Pinpointed issue down to https://github.com/symfony/symfony/blame/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerWeakRefPass.php#L35

This explains why I'm only seeing it during tests. This compiler pass makes a copy of the service with IGNORE_ON_INVALID_REFERENCE, violating its own rules in the later Invalid Reference Behavior check.

@stof
Copy link
Member
stof commented May 24, 2018

@nicolas-grekas how should we handle non-shared services for this test container ?

@nicolas-grekas
Copy link
Member

See #27364

@curry684
Copy link
Contributor Author

If anyone else also got his CI/CD pipelines stuck waiting for this to be fixed, just add a compiler pass temporarily with:

    public function process(ContainerBuilder $container)
    {
        if ($container->has('test.service_container')) {
            $container->setAlias('test.service_container', 'service_container');
        }
    }

@stof
Copy link
Member
stof commented May 25, 2018

@curry684 that won't give you access to the private services though

@curry684
Copy link
Contributor Author

Wasn't using that feature yet anyway as it's a 4.1 exclusive 😉

@stof
Copy link
Member
stof commented May 25, 2018

@curry684 test.service_container is also 4.1 exclusive 😄

@curry684
Copy link
Contributor Author

I had already upgraded my application to 4.1.0-beta2 to test it, but wasn't using the private service tester yet, as the tests kept crashing because of this bug before I could do so 😆

nicolas-grekas added a commit that referenced this issue May 25, 2018
…shared services (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix bad exception on uninitialized references to non-shared services

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27360
| License       | MIT
| Doc PR        | -

This restriction is unneeded complexity that prevents legit use cases (see linked issue #27360).

Commits
-------

8bba68f [DI] Fix bad exception on uninitialized references to non-shared services
@curry684
Copy link
Contributor Author

Confirmed fixed @ https://travis-ci.org/omines/datatables-bundle/jobs/382768689

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

5 participants
0