{"record":{"id":"e3d2b772b2d0b42d","repo":"phacility/phabricator","slug":"this-query-s-does-not-support-sorting-by-orde","errorCode":null,"errorMessage":"This query (\"%s\") does not support sorting by order key \"%s\". Supported orders are: %s.","messagePattern":"This query \\(\"(.+?)\"\\) does not support sorting by order key \"(.+?)\"\\. Supported orders are: (.+?)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php","lineNumber":1056,"sourceCode":"   * To set an order vector, specify a list of order keys as provided by\n   * @{method:getOrderableColumns}.\n   *\n   * @param PhabricatorQueryOrderVector|list<string> List of order keys.\n   * @return this\n   * @task order\n   */\n  public function setOrderVector($vector) {\n    $vector = PhabricatorQueryOrderVector::newFromVector($vector);\n\n    $orderable = $this->getOrderableColumns();\n\n    // Make sure that all the components identify valid columns.\n    $unique = array();\n    foreach ($vector as $order) {\n      $key = $order->getOrderKey();\n      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 '.","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php#L1038-L1074","documentation":"Thrown by PhabricatorCursorPagedPolicyAwareQuery::setOrderVector() when one of the order components' keys does not appear in getOrderableColumns() for this query class. setOrderVector is the low-level API for multi-column ordering across individual orderable columns; every key in the vector must be a column the query has explicitly declared orderable.","triggerScenarios":"Calling setOrderVector(array('title', 'id')) when 'title' is not declared in this query's getOrderableColumns(); referencing a table column that exists in the schema but was never registered as orderable; using an order key valid in another query class.","commonSituations":"Custom application queries where the developer forgot to add the column to getOrderableColumns(); refactors renaming column keys without updating order vectors.","solutions":["Use only keys listed in the exception (they come from array_keys($this->getOrderableColumns()))","If the column genuinely should be sortable, add it to the query's getOrderableColumns() with the right table/column mapping","Prefer the simpler setOrder() with a builtin order unless you truly need a custom vector"],"exampleFix":"// before: 'title' not an orderable column of this query\n$query->setOrderVector(array('title', 'id'));\n\n// after: declare the column orderable in the query class\nprotected function getOrderableColumns() {\n  return parent::getOrderableColumns() + array(\n    'title' => array(\n      'table' => $this->getPrimaryTableAlias(),\n      'column' => 'title',\n      'type' => 'string',\n    ),\n  );\n}","handlingStrategy":"validation","validationCode":"// Validate every vector component against the orderable columns.\n$orderable = $query->getOrderableColumns();\n$vector = array_filter($vector,\n  function ($key) use ($orderable) { return isset($orderable[$key]); });\nif (!$vector) { $vector = array('id'); }\n$query->setOrderVector($vector);","typeGuard":"function isOrderableVector(PhabricatorCursorPagedPolicyAwareQuery $query, array $vector) {\n  $orderable = $query->getOrderableColumns();\n  foreach ($vector as $key) {\n    if (!isset($orderable[$key])) { return false; }\n  }\n  return true;\n}","tryCatchPattern":null,"preventionTips":["Declare every column you intend to sort by in getOrderableColumns() of your query class","Prefer setOrder() with builtin orders unless you need multi-column control"],"tags":["query","sorting","order-vector","phabricator"],"backgroundTag":"invalid-sort-key","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}