{"record":{"id":"adcee070f48bfc16","repo":"phacility/phabricator","slug":"order-vector-s-is-invalid-the-last-column-in-a","errorCode":null,"errorMessage":"Order vector \"%s\" is invalid: the last column in an order must be a column with unique values, but \"%s\" is not unique.","messagePattern":"Order vector \"(.+?)\" is invalid: the last column in an order must be a column with unique values, but \"(.+?)\" is not unique\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php","lineNumber":1072,"sourceCode":"      if (empty($orderable[$key])) {\n        $valid = implode(', ', array_keys($orderable));\n        throw new Exception(\n          pht(\n            'This query (\"%s\") does not support sorting by order key \"%s\". '.\n            'Supported orders are: %s.',\n            get_class($this),\n            $key,\n            $valid));\n      }\n\n      $unique[$key] = idx($orderable[$key], 'unique', false);\n    }\n\n    // Make sure that the last column is unique so that this is a strong\n    // ordering which can be used for paging.\n    $last = last($unique);\n    if ($last !== true) {\n      throw new Exception(\n        pht(\n          'Order vector \"%s\" is invalid: the last column in an order must '.\n          'be a column with unique values, but \"%s\" is not unique.',\n          $vector->getAsString(),\n          last_key($unique)));\n    }\n\n    // Make sure that other columns are not unique; an ordering like \"id, name\"\n    // does not make sense because only \"id\" can ever have an effect.\n    array_pop($unique);\n    foreach ($unique as $key => $is_unique) {\n      if ($is_unique) {\n        throw new Exception(\n          pht(\n            'Order vector \"%s\" is invalid: only the last column in an order '.\n            'may be unique, but \"%s\" is a unique column and not the last '.\n            'column in the order.',\n            $vector->getAsString(),","sourceCodeStart":1054,"sourceCodeEnd":1090,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php#L1054-L1090","documentation":"Thrown by setOrderVector() when the LAST column of the order vector is not marked 'unique' => true in getOrderableColumns(). Cursor paging requires a strong (total) ordering — rows must have a fully deterministic sequence — which is only guaranteed if the final sort column has unique values (typically the object 'id'). Without it, paging could skip or repeat rows, so the API refuses the vector.","triggerScenarios":"setOrderVector(array('title')) where title is a non-unique string column; ordering only by a non-unique status/date column; appending a tiebreaker after a unique column is impossible (that is error 1473), so the unique column must come last.","commonSituations":"Developers sorting by name, priority, or status and forgetting the id tiebreaker; custom orderable columns declared without 'unique' => true used as the final component.","solutions":["Append a unique column (normally 'id') as the final component: setOrderVector(array('title', 'id'))","If your custom column is genuinely unique (e.g. a unique hash), declare 'unique' => true for it in getOrderableColumns()"],"exampleFix":"// before\n$query->setOrderVector(array('title'));\n\n// after\n$query->setOrderVector(array('title', 'id'));","handlingStrategy":"validation","validationCode":"// Guarantee a unique terminator before setting the vector.\n$orderable = $query->getOrderableColumns();\n$last = last($vector);\nif (!idx($orderable[$last], 'unique', false)) {\n  $vector[] = 'id'; // unique on every cursor-paged query\n}\n$query->setOrderVector($vector);","typeGuard":"function vectorEndsUnique(PhabricatorCursorPagedPolicyAwareQuery $query, array $vector) {\n  $orderable = $query->getOrderableColumns();\n  return idx($orderable[last($vector)], 'unique', false) === true;\n}","tryCatchPattern":null,"preventionTips":["End every custom order vector with 'id' (or another column declared 'unique' => true)","Mark custom columns 'unique' => true in getOrderableColumns() only when values are truly unique"],"tags":["query","sorting","order-vector","pagination","phabricator"],"backgroundTag":"invalid-order-vector","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}