phacility/phabricator · error · Exception

This query ("%s") does not support sorting by order key "%s"

Error message

This query ("%s") does not support sorting by order key "%s". Supported orders are: %s.

What it means

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.

Source

Thrown at src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php:1056

   * To set an order vector, specify a list of order keys as provided by
   * @{method:getOrderableColumns}.
   *
   * @param PhabricatorQueryOrderVector|list<string> List of order keys.
   * @return this
   * @task order
   */
  public function setOrderVector($vector) {
    $vector = PhabricatorQueryOrderVector::newFromVector($vector);

    $orderable = $this->getOrderableColumns();

    // Make sure that all the components identify valid columns.
    $unique = array();
    foreach ($vector as $order) {
      $key = $order->getOrderKey();
      if (empty($orderable[$key])) {
        $valid = implode(', ', array_keys($orderable));
        throw new Exception(
          pht(
            'This query ("%s") does not support sorting by order key "%s". '.
            'Supported orders are: %s.',
            get_class($this),
            $key,
            $valid));
      }

      $unique[$key] = idx($orderable[$key], 'unique', false);
    }

    // Make sure that the last column is unique so that this is a strong
    // ordering which can be used for paging.
    $last = last($unique);
    if ($last !== true) {
      throw new Exception(
        pht(
          'Order vector "%s" is invalid: the last column in an order must '.

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Use only keys listed in the exception (they come from array_keys($this->getOrderableColumns()))
  2. If the column genuinely should be sortable, add it to the query's getOrderableColumns() with the right table/column mapping
  3. Prefer the simpler setOrder() with a builtin order unless you truly need a custom vector

Example fix

// before: 'title' not an orderable column of this query
$query->setOrderVector(array('title', 'id'));

// after: declare the column orderable in the query class
protected function getOrderableColumns() {
  return parent::getOrderableColumns() + array(
    'title' => array(
      'table' => $this->getPrimaryTableAlias(),
      'column' => 'title',
      'type' => 'string',
    ),
  );
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate every vector component against the orderable columns.
$orderable = $query->getOrderableColumns();
$vector = array_filter($vector,
  function ($key) use ($orderable) { return isset($orderable[$key]); });
if (!$vector) { $vector = array('id'); }
$query->setOrderVector($vector);

Type guard

function isOrderableVector(PhabricatorCursorPagedPolicyAwareQuery $query, array $vector) {
  $orderable = $query->getOrderableColumns();
  foreach ($vector as $key) {
    if (!isset($orderable[$key])) { return false; }
  }
  return true;
}

Prevention

When it happens

Trigger: 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.

Common situations: Custom application queries where the developer forgot to add the column to getOrderableColumns(); refactors renaming column keys without updating order vectors.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/e3d2b772b2d0b42d. Report an issue: GitHub.