Skip to content

[Dependency Injection] No Circular reference warning for Symfony 3.4 & Doctrine #24775

Closed
@mimol91

Description

@mimol91
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4

Recently I've experienced quite unexpected behavior while using doctrine (#24700) After some deep investigation it seems that reason is simple -> Circular references.

It seems that different Symfony version show or not different errors.

I've tested it on clean Symfony version
It can be simply recreated just just by creating empty class and adding this code to servies.yml

services:
    core.listener.doctrine:
        class: AppBundle\DoctrineListener
        arguments: ['@doctrine.orm.default_entity_manager']
        public: false
        tags:
            - { name: doctrine.orm.entity_listener }

There are three possible solution how application will behave:

Error Id Symfony version Empty cache Service marked as public
1 3.4
1 3.3
0 3.4
0 3.3
0 3.4
2 3.3
0 3.4
0 3.3
Error Id Message
0 No error
1 It's a requirement to specify a Metadata Driver and pass it to Doctrine\ORM\Configuration::setMetadataDriverImpl().
2 Circular reference detected for service "doctrine.orm.default_entity_manager", path: "doctrine.orm.default_entity_manager -> doctrine.orm.default_entity_listener_resolver".

As you can see SF3.4 never mention about circular reference. Which I think still may occur ( or in my case cause some unexpected behavior)
SF 3.3 display (or not ) different error based of condition if service is public or state of cache.

And yes it's again example with Doctrine, however I think DI and circular references are part of Symfony.
(Doctrine version is this same for each of SF version)

Want more magic? Try to install doctrine-migration-bundle (DO NOT register it in AppKernel)
Now if service is private the error about circular reference never shows!

I am totally aware that its not a 'common' case, but I am sure that this missing error about circular reference could save a lot of hours on debugging =). I do not mind if you close this issue, I just try to save other folks time, because they may have similar problem like I do.

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