Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] Fix "almost-circular" dependencies handling #24822

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

Merged
merged 1 commit into from
Nov 5, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 4, 2017

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

In a situation like the following one, we used to trigger a circular reference exception. But this was a false positive, as the reference is resolvable without hitting the circle. Fixing this exception could be considered as a new feature (because no existing config needs it, since it fails). But for 3.4, this should be considered a bug fix, as reported in #24775: not handling this situation now means creating broken service trees.

$containerBuilder = new ContainerBuilder();

$container->register('foo', FooCircular::class)->setPublic(true)
   ->addArgument(new Reference('bar'));

$container->register('bar', BarCircular::class)
    ->addMethodCall('addFoobar', array(new Reference('foobar')));

$container->register('foobar', FoobarCircular::class)
    ->addArgument(new Reference('foo'));

$foo = $containerBuilder->get('foo');

@nicolas-grekas
Copy link
Member Author

(fabbot failure is false positive)

@ogizanagi
Copy link
Contributor

That means FooCircular will get in its constructor a BarCircular instance not fully configured yet (without foobar), right? Isn't it an issue?

@nicolas-grekas
Copy link
Member Author

@ogizanagi how that? I don't think that's the case.

@ogizanagi
Copy link
Contributor

Just trying to dump $bar in FooCircular's constructor:

BarCircular {
  +foobar: null
}

but that's actually the only way to solve the circular dependency AFAIU. Or did I miss something?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Nov 5, 2017

@ogizanagi I'm sorry but I'm not able to reproduce your dump. I added type hints on the classes to ensure that null is not a possible value of the foobar property, and everything still works.

Copy link
Contributor

@ogizanagi ogizanagi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed together on Slack, this is fine actually 👍

@fabpot
Copy link
Member

fabpot commented Nov 5, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit beb4df7 into symfony:3.4 Nov 5, 2017
fabpot added a commit that referenced this pull request Nov 5, 2017
…grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix "almost-circular" dependencies handling

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

In a situation like the following one, we used to trigger a circular reference exception. But this was a false positive, as the reference is resolvable without hitting the circle. Fixing this exception could be considered as a new feature (because no existing config needs it, since it fails). But for 3.4, this should be considered a bug fix, as reported in #24775: not handling this situation now means creating broken service trees.

``` php
$containerBuilder = new ContainerBuilder();

$container->register('foo', FooCircular::class)->setPublic(true)
   ->addArgument(new Reference('bar'));

$container->register('bar', BarCircular::class)
    ->addMethodCall('addFoobar', array(new Reference('foobar')));

$container->register('foobar', FoobarCircular::class)
    ->addArgument(new Reference('foo'));

$foo = $containerBuilder->get('foo');
```

Commits
-------

beb4df7 [DI] Fix "almost-circular" dependencies handling
@nicolas-grekas nicolas-grekas deleted the fix-circ-deps branch November 5, 2017 15:48
This was referenced Nov 5, 2017
nicolas-grekas added a commit that referenced this pull request Nov 20, 2017
…grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Analyze setter-circular deps more precisely

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

This PR reverts the effect of #24828 and #24822 on fixtures, except for the new behavior these PRs introduced, which was mostly fine, but missed a few cases.
This PR now uses the reference graph to precisely decide which services need circular dependency care, and does not touch the other ones.

Commits
-------

9cc4a21 [DI] Analyze setter-circular deps more precisely
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.