8000 [DependencyInjection] Adding an exception on circular reference by nicoweb · Pull Request #28452 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Adding an exception on circular reference #28452

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
wants to merge 1 commit into from

Conversation

nicoweb
Copy link
Contributor
@nicoweb nicoweb commented Sep 12, 2018
Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28312
License MIT
Doc PR -

When a ChildDefinition references itself as parent (or as ancestor in case of longer cycle), an infinite loop happens in the resolution logic.

It's a try to fix this "bug", thank's for your feedback...

Copy link
Member
@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thank you for working on this!
Here are some comments to help move forward.

@@ -1017,6 +1018,10 @@ public function setDefinition($id, Definition $definition)
throw new BadMethodCallException('Adding definition to a compiled container is not allowed');
}

if ($definition instanceof ChildDefinition && $id === $definition->getParent()) {
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest moving the logic to ResolveChildDefinitionsPass.
Also, can't the loop involve intermediary ids? A => B => C => A?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback.
I can move it to ResolveInstanceofConditionalsPass (here), but I think it's not a good option too...
Currently I can't find the way to move it to ResolveChildDefinitionsPass. If you have an idea...

*
* @author Nicolas LEFEVRE <weblefevre@gmail.com>
*/
class ArgumentCircularReferenceException extends RuntimeException
Copy link
Member

Choose a reason for hiding this comment

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

if we want this to make it into a bug fix release, we should not add any new class in the PR (otherwise that'd be a smell for a new feature).
Instead, what about throwing a ServiceCircularReferenceException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, throwing ServiceCircularReferenceException should be a good idea...

@nicolas-grekas
Copy link
Member

Closing in favor of #28480, which is closer to the final patch.
Thank you for working on this and sorry for the collision, that usually doesn't happen...

@nicoweb nicoweb deleted the fix_issue_28312 branch September 18, 2018 02:16
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.

3 participants
0