phacility/phabricator · error · Exception

You can not create a relationship (of type "%s") to object "

Error message

You can not create a relationship (of type "%s") to object "%s" because it is not the right type of object for this relationship.

What it means

Each PhabricatorRelationship class implements canRelateObjects($src, $dst) to enforce type rules (e.g. 'Maniphest Task: subscribers' accepts users/projects, 'Differential Revision: depends on' accepts tasks/revisions). If an added destination object loads fine but fails that type check, this Exception names the relationship constant and the offending PHID; the controller catches it and renders the unrelatable-object response.

Source

Thrown at src/applications/search/controller/PhabricatorSearchRelationshipController.php:102

          $dst_object = idx($dst_objects, $add_phid);
          if (!$dst_object) {
            throw new Exception(
              pht(
                'You can not create a relationship to object "%s" because '.
                'the object does not exist or could not be loaded.',
                $add_phid));
          }

          if ($add_phid == $src_phid) {
            throw new Exception(
              pht(
                'You can not create a relationship to object "%s" because '.
                'objects can not be related to themselves.',
                $add_phid));
          }

          if (!$relationship->canRelateObjects($object, $dst_object)) {
            throw new Exception(
              pht(
                'You can not create a relationship (of type "%s") to object '.
                '"%s" because it is not the right type of object for this '.
                'relationship.',
                $relationship->getRelationshipConstant(),
                $add_phid));
          }
        }
      } catch (Exception $ex) {
        return $this->newUnrelatableObjectResponse($ex, $done_uri);
      }

      $content_source = PhabricatorContentSource::newFromRequest($request);
      $relationship->setContentSource($content_source);

      $editor = $object->getApplicationTransactionEditor()
        ->setActor($viewer)
        ->setContentSource($content_source)

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Pick a target of the type the dialog's typeahead offers - the autocomplete is already filtered by the relationship's allowed object types.
  2. If scripting, validate candidate PHIDs against the relationship before POSTing: $relationship->canRelateObjects($src, $dst) is a public check you can call.
  3. Reload the page to get current dialog configuration after upgrading or changing phabricator/extensions.
  4. Re-read the exception: it names the relationship constant (e.g. 'maniphest.subscribers') so you know which dialog/rule rejected the pair.

Example fix

// before: add whatever the user typed
$phids = explode(';', $request->getStr('phids'));

// after: filter to relatable objects before applying
$phids = array_filter($phids, function ($phid) use ($relationship, $object, $dst_objects) {
  $dst = idx($dst_objects, $phid);
  return $dst && $relationship->canRelateObjects($object, $dst);
});
Defensive patterns

Strategy: validation

Validate before calling

$targets = array();
foreach ($add_phids as $phid) {
  $dst = idx($loadable, $phid);
  if ($dst && $relationship->canRelateObjects($object, $dst)) {
    $targets[] = $phid;
  }
}

Type guard

function isRelatable($relationship, $src, $dst) { return $relationship->canRelateObjects($src, $dst); }

Try / catch

try {
  foreach ($add_phids as $add_phid) { /* ...checks... */ }
} catch (Exception $ex) {
  return $this->newUnrelatableObjectResponse($ex, $done_uri);
}

Prevention

When it happens

Trigger: POSTing a relationship with a valid but wrong-typed target: adding a Diffusion Commit as a task subscriber, adding a user as a 'depends on' task, adding a Monogram-resolved object the typeahead for that dialog should not have offered.

Common situations: Stale dialog after an application extension changed relationship rules in a patch; users pasting arbitrary object monograms/URLs into the tokenizer bypassing its filter; custom code or fork extensions that changed relationship targets without updating dialogs; race where object type changed (e.g. a project converted/archived).

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/54e36338e9b25166. Report an issue: GitHub.