{"record":{"id":"70adb82ba35dc099","repo":"phacility/phabricator","slug":"got-too-many-results-s-for-commit-s-expecte","errorCode":null,"errorMessage":"Got too many results (%s) for commit \"%s\", expected %s.","messagePattern":"Got too many results \\((.+?)\\) for commit \"(.+?)\", expected (.+?)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/repository/storage/PhabricatorRepositoryCommit.php","lineNumber":561,"sourceCode":"      array(\n        'constraints' => array(\n          'repositoryPHIDs' => array($repository->getPHID()),\n          'phids' => array($this->getPHID()),\n        ),\n      ));\n    $result = $future->resolve();\n\n    $commit_display = $this->getMonogram();\n\n    if (empty($result['data'])) {\n      throw new Exception(\n        pht(\n          'Unable to retrieve details for commit \"%s\"!',\n          $commit_display));\n    }\n\n    if (count($result['data']) !== 1) {\n      throw new Exception(\n        pht(\n          'Got too many results (%s) for commit \"%s\", expected %s.',\n          phutil_count($result['data']),\n          $commit_display,\n          1));\n    }\n\n    $record = head($result['data']);\n    $ref_record = idxv($record, array('fields', 'ref'));\n\n    if (!$ref_record) {\n      throw new Exception(\n        pht(\n          'Unable to retrieve CommitRef record for commit \"%s\".',\n          $commit_display));\n    }\n\n    return DiffusionCommitRef::newFromDictionary($ref_record);","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/repository/storage/PhabricatorRepositoryCommit.php#L543-L579","documentation":"Thrown by PhabricatorRepositoryCommit::newCommitRef(), which calls the internal.commit.search Conduit method constrained to a single commit PHID inside one repository (src/applications/repository/storage/PhabricatorRepositoryCommit.php:537-567). Because PHIDs are globally unique, the result set must contain exactly one record; more than one means the storage or query layer returned duplicate commit rows for one PHID. This is an invariant/data-integrity violation, not a user mistake, and is effectively unreachable on a healthy install.","triggerScenarios":"Calling $commit->newCommitRef($viewer) when the repository_commit table contains multiple rows with the same PHID (manual SQL edits, crashed migration, partial DB restore), or when a custom extension corrupts the constraints passed to internal.commit.search so more than one commit matches.","commonSituations":"Database restored from a partial or inconsistent backup; administrators duplicating commit rows with INSERT ... SELECT; third-party plugins hooking DiffusionQuery or the conduit layer. Never occurs during normal git/hg/svn import.","solutions":["Check for duplicates: SELECT phid, COUNT(*) AS n FROM repository_commit GROUP BY phid HAVING n > 1;","Deduplicate the rows (keep the canonical row), after taking a backup","Verify the unique index on the phid column exists and repair the table","If no duplicates exist, audit custom extensions that alter Diffusion commit search or conduit parameter handling"],"exampleFix":"-- before (diagnose)\nSELECT phid, COUNT(*) AS n FROM repository_commit GROUP BY phid HAVING n > 1;\n\n-- after (repair: keep the lowest id per PHID)\nDELETE c1 FROM repository_commit c1\nJOIN repository_commit c2 ON c1.phid = c2.phid AND c1.id > c2.id;","handlingStrategy":"try-catch","validationCode":"$rows = id(new DiffusionCommitQuery())\n  ->setViewer(PhabricatorUser::getOmnipotentUser())\n  ->withPHIDs(array($commit->getPHID()))\n  ->execute();\nif (count($rows) !== 1) {\n  // integrity problem: do not call newCommitRef()\n  return;\n}","typeGuard":null,"tryCatchPattern":"try {\n  $ref = $commit->newCommitRef($viewer);\n} catch (Exception $ex) {\n  // Duplicate rows for one PHID: log the PHID and treat as a data-integrity\n  // incident; do not retry, the input cannot succeed until the DB is fixed.\n  phlog($ex);\n  throw new PhabricatorWorkerPermanentFailureException($ex->getMessage());\n}","preventionTips":["Keep the unique index on repository_commit.phid intact; never bypass it with manual SQL","Take consistent backups so partial restores cannot produce half-duplicated rows","Audit any extension that alters conduit parameters for internal.commit.search"],"tags":["phabricator","diffusion","conduit","data-integrity","duplicate-records","php"],"backgroundTag":"duplicate-database-records","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}