8000 [HttpKernel] Circular reference detected for service "templating" · Issue #6730 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel] Circular reference detected for service "templating" #6730

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
sstok opened this issue Jan 14, 2013 · 12 comments
Closed

[HttpKernel] Circular reference detected for service "templating" #6730

sstok opened this issue Jan 14, 2013 · 12 comments

Comments

@sstok
Copy link
Contributor
sstok commented Jan 14, 2013

Yesterday I started experimenting with Symfony 2.2-beta, but after running the the tests I got the following error.

Circular reference detected for service "templating", path: "templating -> debug.templating.engine.twig -> twig -> twig.extension.httpkernel -> http_content_renderer -> http_content_renderer.strategy.hinclude".

The only thing on the calling line is this $this->container->get('templating').
Its a functional test that does execute any route, so I guess thats the reason why this was not found earlier.

The problem (from what I have found) is because Twig has the twig.extension.httpkernel which relies on the http_content_renderer which in turn calls the http_content_renderer.strategy.hinclude. And http_content_renderer.strategy.hinclude uses the Templating service causing the Circular reference.

When using the Controller this will not happen because the http_content_renderer 'seems' to be executed before any rendering and preventing the Circular reference from happening.

When I disable the hinclude service (comment <tag />) it works.

So the only fix I can think of is to pass the Container to the hinclude service and get the templating service when needed (as described in the docs).

Related to #6459

@MDrollette
Copy link
Contributor

Getting this with KnpPaginator after updating to symfony 2.2

ServiceCircularReferenceException: Circular reference detected for service "templating", path:
"knp_paginator.subscriber.sliding_pagination -> templating -> twig -> twig.extension.httpkernel -> http_content_renderer -> http_content_renderer.strategy.hinclude".

Which seems fixed here: KnpLabs/KnpPaginatorBundle#133

Not sure if it's up to the bundles to change or if it should be changed here?

@sstok
Copy link
Contributor Author
sstok commented Jan 14, 2013

Bundles are one thing, but this breaks the usage of the templating service when used without a request (I believe this will affect console applications as well).

Injecting the container should resolve this (as described in the documentation for Twig extensions).
This should be not problem for Drupal as they use there own hinclude as mentioned by #6459 (comment)

If @fabpot agrees I can work a pull request.

@sstok
Copy link
Contributor Author
sstok commented Jan 16, 2013

@fabpot ping

@fabpot fabpot closed this as completed in 94cb13d Jan 18, 2013
fabpot added a commit that referenced this issue Jan 18, 2013
This PR was merged into the master branch.

Commits
-------

94cb13d [FrameworkBundle] fixed circular reference for service templating (closes #6730, closes #6762)

Discussion
----------

[FrameworkBundle] fixed circular reference for service templating (closes #6730, closes #6762)

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6730, #6762
| License       | MIT
| Doc PR        | n/a

---------------------------------------------------------------------------

by tristanbes at 2013-01-18T14:55:39Z

@fabpot Do you have an idea when you'll merge it please ?
@joelwurtz
Copy link
Contributor

We are still having this issue while getting templating service via a doctrine listener, web requests are fine but when we try to load fixtures we are getting the same error :

[Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException]
Circular reference detected for service "templating", path: "templating -> twig -> twig.extension.httpkernel -> http_content_renderer -> http_content_renderer.strategy.hinclude".

@fabpot
Copy link
Member
fabpot commented Jan 21, 2013

@joelwurtz That's weird. Have you flush your cache? If yes, can you send me your appDevDebugProjectContainer.php file from your project?

@joelwurtz
Copy link
Contributor

Yes, (try the hard way rm -rf app/cache still the same issue), here my appDevDebugProjectContainer.php : https://gist.github.com/7495a23b6a62c216340e

@joelwurtz
Copy link
Contributor

You can reproduce the error easily by using doctrine fixtures and try to do a $this->container->get('templating'); in a fixture file (which implements ContainerAwareInterface of course)

@gimler
Copy link
Contributor
gimler commented Jan 21, 2013

Same problem with the latest version from symfony and NelmioApiDocBundle

@fabpot
Copy link
Member
fabpot commented Jan 21, 2013

ok, I get it now. You have only configured Twig as a templating engine, whereas all other examples were using both PHP and Twig. I'm going to have a look at this issue.

@kriswallsmith
Copy link
Contributor

In the meantime, adding php as a templating engine will fix this issue.

@fabpot
Copy link
Member
fabpot commented Jan 23, 2013

I've just submitted a PR to fix this issue (see #6850). I'm not proud of this workaround, but there is no way we can fix it easily with the way the container works. Can someone confirm that it works before I merge?

@ternel
Copy link
ternel commented Jan 23, 2013

Yup, works for me :) Thx!

@fabpot fabpot closed this as completed in 65b4112 Jan 23, 2013
fabpot added a commit that referenced this issue Jan 23, 2013
This PR was merged into the master branch.

Commits
-------

65b4112 fixed a circular reference (closes #6730)

Discussion
----------

fixed a circular reference (closes #6730)

| Q             | 
7C65
A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #6730
| License       | MIT
| Doc PR        | n/a

---------------------------------------------------------------------------

by stof at 2013-01-23T13:56:19Z

shoudln't this be moved to the component ? Someone using the TwigBridge, HttpKernel and the DI component outside the full stack framework (let's say Drupal maybe) would also face the circular reference issue

---------------------------------------------------------------------------

by fabpot at 2013-01-23T13:58:28Z

No, they won't as the problem is only if you are using the templating component. So, Silex or Drupal won't have the problem.

---------------------------------------------------------------------------

by stof at 2013-01-23T14:01:03Z

ah, the issue is indeed with the TwigEngine, not with the Twig_Environment service.
codekipple pushed a commit to wiredmedia/ToInlineStyleEmailBundle that referenced this issue Feb 5, 2014
…yView() method can't be used and you have to use the setHTML() method directly. The reason for this change is because i was trying to use the bundle in a symfony 2.1 project and 2.1 has this bug symfony/symfony#6730. Once we get off 2.1 we can revert to the master branch.
ollietb pushed a commit to ollietb/ErrorNotifierBundle that referenced this issue Sep 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
0