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

Circular reference when ingecting validator or sec-context and tagging doctrine onFlush event #1111

Closed
Fludimir opened this issue May 6, 2013 · 5 comments

Comments

@Fludimir
Copy link

Fludimir commented May 6, 2013

With FOSUserBundle its unable to create any event listener that requires validator or security-context and subscribed on doctrine onFlush event - you'll get exception

Circular reference detected for service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager -> doctrine.dbal.default_connection -> acme.demo.brokenlistener_validator -> validator -> fos_user.user_manager".

example services:

<!-- circular reference error when enabling fosuserbundle -->
        <service id="acme.demo.brokenlistener_validator" class="Acme\DemoBundle\EventListener\BrokenListenerWithValidator">
            <tag name="doctrine.event_listener" event="onFlush" method="onFlush" />
            <argument type="service" id="validator" />
        </service>
<!-- circular reference error when enabling fosuserbundle -->
        <service id="acme.demo.brokenlistener_sc" class="Acme\DemoBundle\EventListener\BrokenListenerWithSecurityContext">
            <tag name="doctrine.event_listener" event="onFlush" method="onFlush" />
            <argument type="service" id="security.context" />
        </service>
<!-- circular reference error in symfony-standard without fos
        <service id="acme.demo.brokenlistener_em" class="Acme\DemoBundle\EventListener\BrokenListenerWithEntityManager">
            <tag name="doctrine.event_listener" event="onFlush" method="onFlush" />
            <argument type="service" id="doctrine.orm.entity_manager" />
        </service>
        -->
<!-- solution for previous error in symfony-standard -->
        <service id="acme.demo.workinglistener_registry" class="Acme\DemoBundle\EventListener\WorkingListenerWithRegistry">
            <tag name="doctrine.event_listener" event="onFlush" method="onFlush" />
            <argument type="service" id="doctrine" />
        </service>

Only Symfony Standard 2.2 + FOSUserBundle (either 1.3.1 or current master) required to reproduce. Full code without vendors https://docs.google.com/file/d/0B1Q55deL45peWHc1dlFfbmt5ZkE/edit?usp=sharing .

Same problem http://www.9nit.com/php/injecting-securitycontext-services-into-a-listener-class-in-symfony2-causes-circular-reference-error-39161.html

@stof
Copy link
Member

stof commented May 9, 2013

This is not specific to FOSUserBundle. It would be the same for any user provider using Doctrine: if you inject Doctrine in the user provider which is then injected in the security context, you cannot inject the security context into Doctrine again.

@Fludimir
Copy link
Author

Yes, if injecting or (using factory to get) entity_manager directly, but this may be solved by using lazy service "doctrine" and getting manager from it when real call required, or implement another lazy service using ObjectManagerDecorator from Doctrine2.4.

Currently I have to inject service container in all services that need to use doctrine onFlush event, this is really bad and caused lot of troubles. And looks like this is a problem not only for me

@lostedboy
Copy link

Got same problem injecting Twig.

Is there any solution to avoid Circular reference exception and not to include service container?

@XWB
Copy link
Member

XWB commented Nov 28, 2016

Not related to this bundle.

@XWB XWB closed this as completed Nov 28, 2016
@stof
Copy link
Member

stof commented Nov 28, 2016

And btw, this should be fixed by #1615 as we don't inject the user manager in the validator anymore (we only inject the canonical fields updater)

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

4 participants