doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.77k stars 224 forks source link

Graph contains cyclic dependency #236

Closed mvar closed 8 years ago

mvar commented 8 years ago

I run into this exception when I try to load fixtures:

$ bin/console doctrine:fixtures:load -n -vvv
  > purging database

  [Doctrine\Common\DataFixtures\Exception\CircularReferenceException]                                                
  Graph contains cyclic dependency. An example of this problem would be the following: Class C has class B as its d  
  ependency. Then, class B has class A has its dependency. Finally, class A has class C as its dependency.           

Exception trace:
 () at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php:158
 Doctrine\Common\DataFixtures\Sorter\TopologicalSorter->visit() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php:165
 Doctrine\Common\DataFixtures\Sorter\TopologicalSorter->visit() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Sorter/TopologicalSorter.php:112
 Doctrine\Common\DataFixtures\Sorter\TopologicalSorter->sort() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php:197
 Doctrine\Common\DataFixtures\Purger\ORMPurger->getCommitOrder() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php:111
 Doctrine\Common\DataFixtures\Purger\ORMPurger->purge() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php:136
 Doctrine\Common\DataFixtures\Executor\AbstractExecutor->purge() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:85
 Doctrine\Common\DataFixtures\Executor\ORMExecutor->Doctrine\Common\DataFixtures\Executor\{closure}() at n/a:n/a
 call_user_func() at /Users/mantas/Sites/xxx/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:233
 Doctrine\ORM\EntityManager->transactional() at /Users/mantas/Sites/xxx/vendor/doctrine/data-fixtures/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php:90
 Doctrine\Common\DataFixtures\Executor\ORMExecutor->execute() at /Users/mantas/Sites/xxx/vendor/doctrine/doctrine-fixtures-bundle/Command/LoadDataFixturesDoctrineCommand.php:118
 Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand->execute() at /Users/mantas/Sites/xxx/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
 Symfony\Component\Console\Command\Command->run() at /Users/mantas/Sites/xxx/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:831
 Symfony\Component\Console\Application->doRunCommand() at /Users/mantas/Sites/xxx/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:186
 Symfony\Component\Console\Application->doRun() at /Users/mantas/Sites/xxx/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/mantas/Sites/xxx/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:117
 Symfony\Component\Console\Application->run() at /Users/mantas/Sites/xxx/bin/console:29

Fixtures are loaded when using version v1.1.1 of this library. Does not work with v1.2.1 or v1.2.0.

And... how I'm supposed to know where is the issue? Why does exception message prints A, B, C instead of real class names? I have ~100 entities (including embeddables).


More about my case:

I have 3 level hierarchy which is made up with two additional classes. Top and bottom levels extends abstract class (single table inheritance). Middle level is of two types, so it has another abstract class which extends the first one. These levels are connected with parent-children relations which is described in main abstract class. Other classes just holds specific type and setter/getters for parent/children where needed.

I'm not sure what's wrong, but CircularReferenceException exception is thrown while processing main abstract class.

megyland commented 8 years ago

I have the same issue, fixtures are loaded when using v1.1.1 but it doesn't work with v1.2.0 and v1.2.1 and I get the same exception

simoziyadi commented 8 years ago

I also have the same problem could anyone tell me how to fix it.

totaltrash commented 8 years ago

I have the same issue with a schema that uses inheritance see #227.

Renrhaf commented 8 years ago

Same issue here.

cordoval commented 8 years ago

This is because @Ocramius did some refactoring, i had solve it with tying the dependencies instead of

       "doctrine/doctrine-fixtures-bundle": "~2.3.0",
       "doctrine/data-fixtures": "~1.1.1",

to:

     "doctrine/doctrine-fixtures-bundle": "~2.3.0",
     "doctrine/data-fixtures": "1.1.1",

I think there was a wrong tagging somewhere because ~1.1.1 installed 1.2.0 which does not make sense. But in any case, there is your solution we can close this ticket after you guys confirm.

mvar commented 8 years ago

@cordoval sticking to old version is not a solution.

cordoval commented 8 years ago

he he, it seems it is for sylius too. Not saying new code is not good. Just saying old code was not holding me back.

peterrehm commented 8 years ago

There is ongoing work in #231. With the minor improvement in #233 you will see the classes causing the exception.

Ocramius commented 8 years ago

Sticking to 1.1.* is a good-enough solution for now. ORM 2.6 will not be compatible with it, though.

stof commented 8 years ago

@Ocramius the 1.1 version was not breaking on purge for circular references (it may break at the DB level if you don't have ON DELETE behavior configured for your constraints, but it would allow to work with cyclic graphs). Throwing an exception instead of silently accepting cyclic graphs with the same limitation is a BC break, so not good for a minor version. And there is no workaround (contrary to the 1.1.x behavior where you could solve it by changing the ON DELETE behavior of your constraint in the DB)

Jean85 commented 8 years ago

Same issue here too, revert of composer update was the only solving way.

@Ocramius , why are you stopping to support cyclic definitions of entities? It's commonly used...

stof commented 8 years ago

@Ocramius I think we would need to have a way to make the TopologicalSorter accept cyclic references for entities (their order is then undefined, and you have to ensure that the DB constraints can handle the removal of cycles) but keep being strict for the sorting of fixtures