{"record":{"id":"8accde1620eb9639","repo":"phacility/phabricator","slug":"diff-s-does-not-exist","errorCode":null,"errorMessage":"Diff \"%s\" does not exist!","messagePattern":"Diff \"(.+?)\" does not exist!","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/differential/editor/DifferentialTransactionEditor.php","lineNumber":1020,"sourceCode":"    $body->addHTMLSection($header, $section_html);\n  }\n\n  private function loadDiff($phid, $need_changesets = false) {\n    $query = id(new DifferentialDiffQuery())\n      ->withPHIDs(array($phid))\n      ->setViewer($this->getActor());\n\n    if ($need_changesets) {\n      $query->needChangesets(true);\n    }\n\n    return $query->executeOne();\n  }\n\n  public function requireDiff($phid, $need_changesets = false) {\n    $diff = $this->loadDiff($phid, $need_changesets);\n    if (!$diff) {\n      throw new Exception(pht('Diff \"%s\" does not exist!', $phid));\n    }\n\n    return $diff;\n  }\n\n/* -(  Herald Integration  )------------------------------------------------- */\n\n  protected function shouldApplyHeraldRules(\n    PhabricatorLiskDAO $object,\n    array $xactions) {\n    return true;\n  }\n\n  protected function didApplyHeraldRules(\n    PhabricatorLiskDAO $object,\n    HeraldAdapter $adapter,\n    HeraldTranscript $transcript) {\n","sourceCodeStart":1002,"sourceCodeEnd":1038,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/differential/editor/DifferentialTransactionEditor.php#L1002-L1038","documentation":"DifferentialTransactionEditor::requireDiff() loads a DifferentialDiff by PHID through DifferentialDiffQuery (with the editor's actor as viewer, optionally loading changesets) and throws when the query returns nothing. It fires during revision transaction application whenever a transaction references a diff PHID the actor cannot see or that no longer exists. Typical producers are 'differential.revision.edit' Conduit calls and internal code that applies DifferentialRevisionTransaction TYPE_UPDATE style transactions.","triggerScenarios":"Applying an update transaction with a diff PHID that was deleted or belongs to another install; passing a malformed PHID (e.g., a revision PHID 'PHID-DREV-...' instead of 'PHID-DIFF-...'); the acting user lacking view policy on the repository/revision that owns the diff; automation reusing a cached diff PHID after the diff was destroyed.","commonSituations":"Scripts or bots that cache PHIDs across runs; Conduit clients that copy data between Phabricator instances; imports where the diff was created but the transaction batch references a stale identifier; policy-restricted repositories making the diff invisible to the acting user.","solutions":["Validate the PHID prefix is 'PHID-DIFF-' and load it first with DifferentialDiffQuery using the same viewer before applying transactions","If automating updates, resolve the target revision's current active diff via DifferentialRevisionQuery->needActiveDiffs(true) instead of caching a PHID","Check that the acting user has view permission on the diff's repository and revision (policies are enforced because the query is viewer-scoped)","If the diff was legitimately deleted, drop the stale reference from your transaction set or create a new diff first"],"exampleFix":"// before\n$editor->applyTransactions($revision, array(\n  id(new DifferentialRevisionTransaction())\n    ->setTransactionType(DifferentialTransactionType::TYPE_UPDATE)\n    ->setNewValue($stale_diff_phid),\n));\n\n// after\n$diff = id(new DifferentialDiffQuery())\n  ->setViewer($actor)\n  ->withPHIDs(array($stale_diff_phid))\n  ->executeOne();\nif (!$diff) {\n  $revision_x = id(new DifferentialRevisionQuery())\n    ->setViewer($actor)\n    ->withIDs(array($revision->getID()))\n    ->needActiveDiffs(true)\n    ->executeOne();\n  $diff = $revision_x->getActiveDiff();\n}\n// then use $diff->getPHID() in the transaction","handlingStrategy":"validation","validationCode":"// Before applying an update transaction, confirm the diff is visible:\n$diff = id(new DifferentialDiffQuery())\n  ->setViewer($actor)\n  ->withPHIDs(array($diff_phid))\n  ->executeOne();\nif (!$diff) {\n  // do not call the editor with this PHID; resolve the active diff instead\n  return; \n}","typeGuard":"function isDiffPHID($phid) {\n  return is_string($phid) && preg_match('/^PHID-DIFF-/', $phid);\n}","tryCatchPattern":"try {\n  $diff = $editor->requireDiff($diff_phid);\n} catch (Exception $ex) {\n  // Treat as stale reference: re-resolve the revision's active diff\n  // and skip or rebuild the transaction instead of failing the batch.\n  $diff = null;\n}","preventionTips":["Never cache diff PHIDs across runs; resolve the revision's active diff with needActiveDiffs(true) at call time","Validate PHID prefixes (PHID-DIFF-) before constructing transactions","Run lookups with the same viewer that will apply the transactions so policy failures surface early"],"tags":["phabricator","differential","diff","phid","not-found","transaction-editor"],"backgroundTag":"entity-not-found","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}