{"record":{"id":"befa48136e7a0f34","repo":"phacility/phabricator","slug":"query-s-does-not-support-a-builtin-order-s","errorCode":null,"errorMessage":"Query \"%s\" does not support a builtin order \"%s\". Supported orders are: %s.","messagePattern":"Query \"(.+?)\" does not support a builtin order \"(.+?)\"\\. Supported orders are: (.+?)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php","lineNumber":892,"sourceCode":"   *\n   * This is a high-level method which selects an ordering from a predefined\n   * list of builtin orders, as provided by @{method:getBuiltinOrders}. These\n   * options are user-facing and not exhaustive, but are generally convenient\n   * and meaningful.\n   *\n   * You can also use @{method:setOrderVector} to specify a low-level ordering\n   * across individual orderable columns. This offers greater control but is\n   * also more involved.\n   *\n   * @param string Key of a builtin order supported by this query.\n   * @return this\n   * @task order\n   */\n  public function setOrder($order) {\n    $aliases = $this->getBuiltinOrderAliasMap();\n\n    if (empty($aliases[$order])) {\n      throw new Exception(\n        pht(\n          'Query \"%s\" does not support a builtin order \"%s\". Supported orders '.\n          'are: %s.',\n          get_class($this),\n          $order,\n          implode(', ', array_keys($aliases))));\n    }\n\n    $this->builtinOrder = $aliases[$order];\n    $this->orderVector = null;\n\n    return $this;\n  }\n\n\n  /**\n   * Set a grouping order to apply before primary result ordering.\n   *","sourceCodeStart":874,"sourceCodeEnd":910,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php#L874-L910","documentation":"Thrown by PhabricatorCursorPagedPolicyAwareQuery::setOrder() when the requested order key is not present in getBuiltinOrderAliasMap() for the concrete query class. Builtin orders are the named, ready-made sort orders each application query defines (with aliases); the exception message lists every supported key, so it is self-describing.","triggerScenarios":"Calling setOrder('priority') on a query class whose builtin orders are only e.g. 'name', 'age', 'id'; using an alias only supported by a different query class; passing null or a typo'd key.","commonSituations":"Copy-pasting sort logic between query classes that support different orders; upgrading Phabricator when a builtin order is renamed or removed; constructing queries dynamically from user input without whitelisting.","solutions":["Read the exception message: it enumerates the supported orders for the exact query class — pick one of those","Whitelist user-supplied sort keys against array_keys($query->getBuiltinOrderAliasMap()) before calling setOrder()","For custom orderings, define the columns in getOrderableColumns() and use setOrderVector() instead"],"exampleFix":"// before\n$query->setOrder($user_supplied_order);\n\n// after: whitelist before applying\n$aliases = $query->getBuiltinOrderAliasMap();\nif (isset($aliases[$user_supplied_order])) {\n  $query->setOrder($user_supplied_order);\n} else {\n  $query->setOrder('id');\n}","handlingStrategy":"validation","validationCode":"// Whitelist against the query's own alias map before calling setOrder().\n$aliases = $query->getBuiltinOrderAliasMap();\nif (!isset($aliases[$order])) {\n  $order = 'id'; // safe default present on virtually all queries\n}\n$query->setOrder($order);","typeGuard":"function isValidBuiltinOrder(PhabricatorCursorPagedPolicyAwareQuery $query, $order) {\n  return isset($query->getBuiltinOrderAliasMap()[$order]);\n}","tryCatchPattern":null,"preventionTips":["Never pass user input straight to setOrder(); validate against getBuiltinOrderAliasMap() first","When copying query code between applications, re-check that the target query supports the same orders"],"tags":["query","sorting","order","phabricator"],"backgroundTag":"invalid-sort-key","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}