Skip to content

Doctrine Listener not loaded lazily doctrine-bridge #31683

Closed
@zghosts

Description

@zghosts

Symfony version(s) affected: 3.4.28

Description
Since symfony 3.4.28 a "Circular reference detected for service" exception is thrown on cache warmup.

How to reproduce
This seems to be tied to doctrine eventlisteners which get Repository services injected, which should be lazy loaded, but arn't.

comment beforehand: I know listeners should only listen to one event, but I have my reasons for doing this.

my configuration is something similar to:

class EventListener {
    private $repository;

    public function __construct(SomeRepositoryService $repository)
    {
         $this->repository = $repository;
    }

    public function postPersist(LifecycleEventArgs $event)
    {
        //Do something
    }
    public function preRemove(LifecycleEventArgs $event)
    {
        //Do something
    }
}

ServiceDefinition:

EventListener:
    tags:
        - { name: doctrine.event_listener, connection: default, event: postPersist, priority: 10, lazy: true }
        - { name: doctrine.event_listener, connection: default, event: preRemove, priority: 10, lazy: true }

Possible Solution
I've trace this back to recent changes in the doctrine-bridge, specifically line 72-75 which seems to always initialize all listeners even if they should be lazy loaded.

Restoring old behaviour by removing the foreach loop fixes the issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions