{"record":{"id":"ae7d7cdcbbc15c3a","repo":"phacility/phabricator","slug":"query-key-s-does-not-correspond-to-a-valid-quer","errorCode":null,"errorMessage":"Query key \"%s\" does not correspond to a valid query.","messagePattern":"Query key \"(.+?)\" does not correspond to a valid query\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/search/engine/PhabricatorApplicationSearchEngine.php","lineNumber":1150,"sourceCode":"  }\n\n  public function buildConduitResponse(\n    ConduitAPIRequest $request,\n    ConduitAPIMethod $method) {\n    $viewer = $this->requireViewer();\n\n    $query_key = $request->getValue('queryKey');\n    if ($query_key === null || !strlen($query_key)) {\n      $saved_query = new PhabricatorSavedQuery();\n    } else if ($this->isBuiltinQuery($query_key)) {\n      $saved_query = $this->buildSavedQueryFromBuiltin($query_key);\n    } else {\n      $saved_query = id(new PhabricatorSavedQueryQuery())\n        ->setViewer($viewer)\n        ->withQueryKeys(array($query_key))\n        ->executeOne();\n      if (!$saved_query) {\n        throw new Exception(\n          pht(\n            'Query key \"%s\" does not correspond to a valid query.',\n            $query_key));\n      }\n    }\n\n    $constraints = $request->getValue('constraints', array());\n    if (!is_array($constraints)) {\n      throw new Exception(\n        pht(\n          'Parameter \"constraints\" must be a map of constraints, got \"%s\".',\n          phutil_describe_type($constraints)));\n    }\n\n    $fields = $this->getSearchFieldsForConduit();\n\n    foreach ($fields as $key => $field) {\n      if (!$field->getConduitParameterType()) {","sourceCodeStart":1132,"sourceCodeEnd":1168,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/engine/PhabricatorApplicationSearchEngine.php#L1132-L1168","documentation":"In buildQueryFromRequest() (used by every generated `<app>.search` Conduit method), when the request supplies a non-empty 'queryKey' that is neither a builtin key (like 'all' or 'open') nor a loadable PhabricatorSavedQuery row, a plain Exception is thrown. Query keys come from saved/named queries in the UI; the lookup is scoped to the current viewer, so a valid key owned by another user also resolves to nothing and fails here.","triggerScenarios":"Conduit call `maniphest.search { \"queryKey\": \"Xyz\" }` where 'Xyz' is typo'd, belongs to another user, was deleted (user removed the saved query), or is a builtin key the engine does not expose (isBuiltinQuery() false for that engine). Also custom code calling buildSavedQueryFromBuiltin()/buildQueryFromRequest directly.","commonSituations":"Scripts hardcoding a saved-query key after its owner deleted or renamed it; sharing API snippets between accounts (saved queries are per-user); passing an engine-internal query key that is not marked builtin for that application; copy-pasting the query parameter from a Diffusion URL instead of the actual queryKey.","solutions":["List the user's valid keys first: call the app's `<app>.search` with no queryKey or fetch `user.query` style saved queries; simplest is to open the saved query in the UI and copy the queryKey from its URL.","If the key belongs to another user, re-create the saved query under the account making the Conduit call, or use builtin keys ('all', 'open', 'authored') which are always valid.","Stop passing the key entirely and send explicit 'constraints' in the Conduit request instead - constraints are stable and independent of user-saved state.","Check for typos: keys are case-sensitive and alphanumeric."],"exampleFix":"// before\n{\n  \"method\": \"maniphest.search\",\n  \"params\": { \"queryKey\": \"OthrUsersKey\" }\n}\n\n// after: express the same filter with constraints\n{\n  \"method\": \"maniphest.search\",\n  \"params\": { \"constraints\": { \"statuses\": [\"open\"], \"projects\": [\"infra\"] } }\n}","handlingStrategy":"validation","validationCode":"// Validate a query key before using it\n$builtin = $engine->getBuiltinQueries();\nif (!isset($builtin[$query_key])) {\n  $saved = id(new PhabricatorSavedQueryQuery())\n    ->setViewer($viewer)\n    ->withQueryKeys(array($query_key))\n    ->executeOne();\n  if (!$saved) { $query_key = null; } // fall back to defaults/constraints\n}","typeGuard":"function isValidQueryKey($engine, $viewer, $key) { return $engine->isBuiltinQuery($key) || (bool)id(new PhabricatorSavedQueryQuery())->setViewer($viewer)->withQueryKeys(array($key))->executeOne(); }","tryCatchPattern":"try {\n  $saved = $engine->buildQueryFromRequest($request);\n} catch (Exception $ex) {\n  // degrade to default query rather than failing the whole API call\n  $request->setValue('queryKey', null);\n  $saved = $engine->buildQueryFromRequest($request);\n}","preventionTips":["Prefer explicit constraints over saved queryKeys in integrations","Store query keys in configuration and validate them after each Phabricator upgrade","Remember saved queries are per-user: integration users need their own saved queries"],"tags":["phabricator","conduit","search","query-key","api"],"backgroundTag":"invalid-query-key","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}