{"record":{"id":"c81ea680b31990b8","repo":"phacility/phabricator","slug":"you-can-not-create-a-relationship-to-object-s-b","errorCode":null,"errorMessage":"You can not create a relationship to object \"%s\" because the object does not exist or could not be loaded.","messagePattern":"You can not create a relationship to object \"(.+?)\" because the object does not exist or could not be loaded\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/search/controller/PhabricatorSearchRelationshipController.php","lineNumber":86,"sourceCode":"      $capabilities = $relationship->getRequiredRelationshipCapabilities();\n\n      if ($all_phids) {\n        $dst_objects = id(new PhabricatorObjectQuery())\n          ->setViewer($viewer)\n          ->withPHIDs($all_phids)\n          ->setRaisePolicyExceptions(true)\n          ->requireCapabilities($capabilities)\n          ->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 '.","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/controller/PhabricatorSearchRelationshipController.php#L68-L104","documentation":"While applying relationship edits, the controller looked up each added PHID via PhabricatorObjectQuery with policy exceptions raised; an add_phid was absent from the loaded $dst_objects map, meaning the object does not exist (deleted, bad PHID) or the acting user cannot see it (policy-filtered). The exception is caught and converted into an 'unrelatable object' dialog response (newUnrelatableObjectResponse), so users normally see a friendly error instead of the raw message.","triggerScenarios":"POSTing a relationship add with a PHID that was just deleted (task merged/deactivated, project archived), a malformed PHID string, or a PHID for an object the viewer has no permission to see (private project, restricted task) - typical when the dialog sat open in a stale tab while the target was removed elsewhere.","commonSituations":"Stale browser tabs: user opens 'Edit Subscribers', target object is deleted by someone else, submit then fails; copy-pasting PHIDs from old email/URLs where the object was later removed; policy misconfigurations where the user can reference but not load an object.","solutions":["Reload the page and reopen the relationship dialog - the typeahead will no longer offer the deleted/invisible object.","Verify the PHID still exists and is visible to the acting user (e.g. via `phid.query` Conduit call) before re-adding.","If scripting, resolve names to PHIDs fresh at request time instead of caching PHIDs long-term.","Check the object's view policy if you suspect permissions: the load fails silently for hidden objects and surfaces as this same error."],"exampleFix":"// before: using a possibly stale PHID captured earlier\n$request->setStr('phids', $old_phid);\n\n// after: re-resolve right before the call\n$results = id(new ConduitCall('phid.query', array('phids' => array($old_phid))))->execute();\nif (empty($results[$old_phid])) { /* object gone; skip */ }","handlingStrategy":"try-catch","validationCode":"// Resolve PHIDs through the viewer before building the add list\n$visible = id(new PhabricatorObjectQuery())\n  ->setViewer($viewer)\n  ->withPHIDs($add_phids)\n  ->execute();\n$add_phids = array_intersect($add_phids, mpull($visible, 'getPHID'));","typeGuard":"function phidExistsForViewer($viewer, $phid) { $o = id(new PhabricatorObjectQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne(); return (bool)$o; }","tryCatchPattern":"try {\n  $editor->applyTransactions($object, $xactions);\n} catch (Exception $ex) {\n  return $this->newUnrelatableObjectResponse($ex, $done_uri); // dialog, not a 500\n}","preventionTips":["Re-resolve PHIDs at request time; never cache them long-term in scripts","Close and reopen stale dialogs after long editing sessions","Verify object visibility with the acting user's session when scripting bulk edits"],"tags":["phabricator","relationships","object-not-found","policy","stale-state"],"backgroundTag":"related-object-not-loadable","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}