phacility/phabricator · error · Exception

Failed to load saved query ("%s").

Error message

Failed to load saved query ("%s").

What it means

Thrown by the export engine's bulk worker job when it cannot load the saved query referenced by the job's 'queryKey' parameter. The worker first checks whether the key names a builtin query (via the search engine's buildSavedQueryFromBuiltin()), then tries to load a persisted PhabricatorSavedQuery by query key with the acting user as viewer. If both paths return nothing (including when policy filtering hides the saved query from the actor), the job aborts.

Source

Thrown at src/infrastructure/export/engine/PhabricatorExportEngineBulkJobType.php:78

    }

    $engine = newv($engine_class, array())
      ->setViewer($actor);

    $query_key = $job->getParameter('queryKey');
    if ($engine->isBuiltinQuery($query_key)) {
      $saved_query = $engine->buildSavedQueryFromBuiltin($query_key);
    } else if ($query_key) {
      $saved_query = id(new PhabricatorSavedQueryQuery())
        ->setViewer($actor)
        ->withQueryKeys(array($query_key))
        ->executeOne();
    } else {
      $saved_query = null;
    }

    if (!$saved_query) {
      throw new Exception(
        pht(
          'Failed to load saved query ("%s").',
          $query_key));
    }

    $format_key = $job->getParameter('formatKey');

    $all_formats = PhabricatorExportFormat::getAllExportFormats();
    $format = idx($all_formats, $format_key);
    if (!$format) {
      throw new Exception(
        pht(
          'Unknown export format ("%s").',
          $format_key));
    }

    if (!$format->isExportFormatEnabled()) {
      throw new Exception(

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Re-run the export from a saved query that currently exists and is visible to the exporting user
  2. Verify the 'queryKey' job parameter is non-empty and matches an existing saved query (or a supported builtin key like 'all' or 'modern')
  3. Confirm the acting user passes the saved query's policy (test by running the same search in the UI as that user)
  4. If the key is builtin, check the search engine's buildSavedQueryFromBuiltin() actually handles that key

Example fix

// before: queueing export with an unvalidated query key
$job->setParameter('queryKey', $maybe_stale_key);

// after: verify the saved query resolves for this actor before queueing
$saved = id(new PhabricatorSavedQueryQuery())
  ->setViewer($actor)
  ->withQueryKeys(array($query_key))
  ->executeOne();
if (!$saved && !$engine->isBuiltinQuery($query_key)) {
  throw new Exception(pht('Query "%s" no longer exists.', $query_key));
}
$job->setParameter('queryKey', $query_key);
Defensive patterns

Strategy: validation

Validate before calling

// Before queueing an export job, confirm the saved query resolves
// for the acting user (or is a supported builtin key).
$engine = $application->newSearchEngine();
if ($engine->isBuiltinQuery($query_key)) {
  $ok = (bool)$engine->buildSavedQueryFromBuiltin($query_key);
} else {
  $ok = (bool)id(new PhabricatorSavedQueryQuery())
    ->setViewer($actor)
    ->withQueryKeys(array($query_key))
    ->executeOne();
}
if (!$ok) {
  // refuse to queue; ask the user to re-save the query
}

Try / catch

try { $engine_bulk->runJob($job); } catch (Exception $ex) { if (preg_match('/Failed to load saved query/', $ex->getMessage())) { /* mark job failed, tell user to recreate the export */ } throw $ex; }

Prevention

When it happens

Trigger: Queueing an export against a saved query that is deleted before the worker runs; passing a custom queryKey that was never persisted; running the job as an actor who cannot see the saved query (executeOne() returns null after policy filtering); passing a builtin key the engine does not implement.

Common situations: A user deletes or renames a saved search while a queued export job is still pending; export initiated from a stale browser session whose query key no longer exists; scripts queueing export jobs with hand-built parameters.

Related errors


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