{"record":{"id":"42af671a9dde72ff","repo":"phacility/phabricator","slug":"failed-to-load-saved-query-s","errorCode":null,"errorMessage":"Failed to load saved query (\"%s\").","messagePattern":"Failed to load saved query \\(\"(.+?)\"\\)\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/infrastructure/export/engine/PhabricatorExportEngineBulkJobType.php","lineNumber":78,"sourceCode":"    }\n\n    $engine = newv($engine_class, array())\n      ->setViewer($actor);\n\n    $query_key = $job->getParameter('queryKey');\n    if ($engine->isBuiltinQuery($query_key)) {\n      $saved_query = $engine->buildSavedQueryFromBuiltin($query_key);\n    } else if ($query_key) {\n      $saved_query = id(new PhabricatorSavedQueryQuery())\n        ->setViewer($actor)\n        ->withQueryKeys(array($query_key))\n        ->executeOne();\n    } else {\n      $saved_query = null;\n    }\n\n    if (!$saved_query) {\n      throw new Exception(\n        pht(\n          'Failed to load saved query (\"%s\").',\n          $query_key));\n    }\n\n    $format_key = $job->getParameter('formatKey');\n\n    $all_formats = PhabricatorExportFormat::getAllExportFormats();\n    $format = idx($all_formats, $format_key);\n    if (!$format) {\n      throw new Exception(\n        pht(\n          'Unknown export format (\"%s\").',\n          $format_key));\n    }\n\n    if (!$format->isExportFormatEnabled()) {\n      throw new Exception(","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/export/engine/PhabricatorExportEngineBulkJobType.php#L60-L96","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run the export from a saved query that currently exists and is visible to the exporting user","Verify the 'queryKey' job parameter is non-empty and matches an existing saved query (or a supported builtin key like 'all' or 'modern')","Confirm the acting user passes the saved query's policy (test by running the same search in the UI as that user)","If the key is builtin, check the search engine's buildSavedQueryFromBuiltin() actually handles that key"],"exampleFix":"// before: queueing export with an unvalidated query key\n$job->setParameter('queryKey', $maybe_stale_key);\n\n// after: verify the saved query resolves for this actor before queueing\n$saved = id(new PhabricatorSavedQueryQuery())\n  ->setViewer($actor)\n  ->withQueryKeys(array($query_key))\n  ->executeOne();\nif (!$saved && !$engine->isBuiltinQuery($query_key)) {\n  throw new Exception(pht('Query \"%s\" no longer exists.', $query_key));\n}\n$job->setParameter('queryKey', $query_key);","handlingStrategy":"validation","validationCode":"// Before queueing an export job, confirm the saved query resolves\n// for the acting user (or is a supported builtin key).\n$engine = $application->newSearchEngine();\nif ($engine->isBuiltinQuery($query_key)) {\n  $ok = (bool)$engine->buildSavedQueryFromBuiltin($query_key);\n} else {\n  $ok = (bool)id(new PhabricatorSavedQueryQuery())\n    ->setViewer($actor)\n    ->withQueryKeys(array($query_key))\n    ->executeOne();\n}\nif (!$ok) {\n  // refuse to queue; ask the user to re-save the query\n}","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Always initiate exports from a query you just ran successfully in the same session","Do not delete or rename saved searches while export jobs are queued in the worker queue","When queueing jobs programmatically, resolve the saved query first and pass its verified key"],"tags":["export","saved-query","bulk-job","phabricator"],"backgroundTag":"invalid-query-reference","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}