{"record":{"id":"bba9b0a17d9b41f6","repo":"phacility/phabricator","slug":"you-can-not-create-a-relationship-to-object-s-b-bba9b0","errorCode":null,"errorMessage":"You can not create a relationship to object \"%s\" because objects can not be related to themselves.","messagePattern":"You can not create a relationship to object \"(.+?)\" because objects can not be related to themselves\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/search/controller/PhabricatorSearchRelationshipController.php","lineNumber":94,"sourceCode":"          ->execute();\n        $dst_objects = mpull($dst_objects, null, 'getPHID');\n      } else {\n        $dst_objects = array();\n      }\n\n      try {\n        foreach ($add_phids as $add_phid) {\n          $dst_object = idx($dst_objects, $add_phid);\n          if (!$dst_object) {\n            throw new Exception(\n              pht(\n                'You can not create a relationship to object \"%s\" because '.\n                'the object does not exist or could not be loaded.',\n                $add_phid));\n          }\n\n          if ($add_phid == $src_phid) {\n            throw new Exception(\n              pht(\n                'You can not create a relationship to object \"%s\" because '.\n                'objects can not be related to themselves.',\n                $add_phid));\n          }\n\n          if (!$relationship->canRelateObjects($object, $dst_object)) {\n            throw new Exception(\n              pht(\n                'You can not create a relationship (of type \"%s\") to object '.\n                '\"%s\" because it is not the right type of object for this '.\n                'relationship.',\n                $relationship->getRelationshipConstant(),\n                $add_phid));\n          }\n        }\n      } catch (Exception $ex) {\n        return $this->newUnrelatableObjectResponse($ex, $done_uri);","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/controller/PhabricatorSearchRelationshipController.php#L76-L112","documentation":"The relationship controller forbids relating an object to itself: while looping over added PHIDs, any $add_phid equal to the source object's $src_phid triggers this Exception (caught and shown as an unrelatable-object dialog). Self-referential edges would create nonsense like 'task T depends on task T' and can loop graph algorithms, so they are rejected outright.","triggerScenarios":"POSTing the object's own PHID in the add list - e.g. adding a task to its own subscribers, setting a task as blocking itself ('Maniphest Task: T123'), or dragging the same object into its relationship tokenizer via paste (paste the current object's URI, which the tokenizer resolves to its PHID).","commonSituations":"Users pasting the object URL into the dialog's typeahead out of curiosity; scripts that compute related-object sets with an off-by-one including the root; merging tasks where source and destination coincide.","solutions":["Exclude the source PHID from any list you feed to the dialog: array_diff($phids, array($src_phid)).","If you hit it in the UI, just remove the object from the selection - the dialog shows which PHID offended in the message.","For scripts, filter self-references before building the request.","No configuration exists to allow self-relationships; model true self-loops differently (e.g. a separate linked-object field)."],"exampleFix":"// before\n$add_phids = array_diff($phids, $initial_phids);\n\n// after: also drop self-references\n$add_phids = array_diff($phids, $initial_phids, array($src_phid));","handlingStrategy":"validation","validationCode":"$add_phids = array_diff($phids, $initial_phids, array($src_phid));","typeGuard":"function hasNoSelfReference($src_phid, array $add_phids) { return !in_array($src_phid, $add_phids, true); }","tryCatchPattern":"try {\n  $this->applyRelationshipChanges($object, $add, $rem);\n} catch (Exception $ex) {\n  return $this->newUnrelatableObjectResponse($ex, $done_uri);\n}","preventionTips":["Filter the current object's PHID out of any generated list before POST","Typeahead config for relationship dialogs should exclude the source object","When computing dependency graphs in scripts, skip edges where src === dst"],"tags":["phabricator","relationships","self-reference","validation","controller"],"backgroundTag":"self-relationship-blocked","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}