{"record":{"id":"6b4b25261e47275b","repo":"doctrine/orm","slug":"a-cycle-has-been-detected-so-a-topological-sort-i","errorCode":null,"errorMessage":"A cycle has been detected, so a topological sort is not possible. The getCycle() method provides the list of nodes that form the cycle.","messagePattern":"A cycle has been detected, so a topological sort is not possible\\. The getCycle\\(\\) method provides the list of nodes that form the cycle\\.","errorType":"exception","errorClass":"Doctrine\\ORM\\Internal\\TopologicalSort\\CycleDetectedException","httpStatus":null,"severity":"error","filePath":"src/Internal/TopologicalSort.php","lineNumber":110,"sourceCode":"     *\n     * @return list<object>\n     */\n    public function sort(): array\n    {\n        foreach (array_keys($this->nodes) as $oid) {\n            if ($this->states[$oid] === self::NOT_VISITED) {\n                $this->visit($oid);\n            }\n        }\n\n        return $this->sortResult;\n    }\n\n    private function visit(int $oid): void\n    {\n        if ($this->states[$oid] === self::IN_PROGRESS) {\n            // This node is already on the current DFS stack. We've found a cycle!\n            throw new CycleDetectedException($this->nodes[$oid]);\n        }\n\n        if ($this->states[$oid] === self::VISITED) {\n            // We've reached a node that we've already seen, including all\n            // other nodes that are reachable from here. We're done here, return.\n            return;\n        }\n\n        $this->states[$oid] = self::IN_PROGRESS;\n\n        // Continue the DFS downwards the edge list\n        foreach ($this->edges[$oid] as $adjacentId => $optional) {\n            try {\n                $this->visit($adjacentId);\n            } catch (CycleDetectedException $exception) {\n                if ($exception->isCycleCollected()) {\n                    // There is a complete cycle downstream of the current node. We cannot\n                    // do anything about that anymore.","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Internal/TopologicalSort.php#L92-L128","documentation":"Error \"A cycle has been detected, so a topological sort is not possible. The getCycle() method provides the list of nodes that form the cycle.\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Internal/TopologicalSort.php:110 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}