{"record":{"id":"19f7826c7b277742","repo":"phacility/phabricator","slug":"constraint-s-is-not-a-valid-constraint-for-this","errorCode":null,"errorMessage":"Constraint \"%s\" is not a valid constraint for this query.","messagePattern":"Constraint \"(.+?)\" is not a valid constraint for this query\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/search/engine/PhabricatorApplicationSearchEngine.php","lineNumber":1182,"sourceCode":"\n    $fields = $this->getSearchFieldsForConduit();\n\n    foreach ($fields as $key => $field) {\n      if (!$field->getConduitParameterType()) {\n        unset($fields[$key]);\n      }\n    }\n\n    $valid_constraints = array();\n    foreach ($fields as $field) {\n      foreach ($field->getValidConstraintKeys() as $key) {\n        $valid_constraints[$key] = true;\n      }\n    }\n\n    foreach ($constraints as $key => $constraint) {\n      if (empty($valid_constraints[$key])) {\n        throw new Exception(\n          pht(\n            'Constraint \"%s\" is not a valid constraint for this query.',\n            $key));\n      }\n    }\n\n    foreach ($fields as $field) {\n      if (!$field->getValueExistsInConduitRequest($constraints)) {\n        continue;\n      }\n\n      $value = $field->readValueFromConduitRequest(\n        $constraints,\n        $request->getIsStrictlyTyped());\n      $saved_query->setParameter($field->getKey(), $value);\n    }\n\n    // NOTE: Currently, when running an ad-hoc query we never persist it into","sourceCodeStart":1164,"sourceCodeEnd":1200,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/search/engine/PhabricatorApplicationSearchEngine.php#L1164-L1200","documentation":"After validating that 'constraints' is a map, the engine collects every legal constraint key from the search engine's fields (getValidConstraintKeys()) and rejects any submitted key not in that set. This catches misspelled or unsupported constraint names before query construction, e.g. asking `maniphest.search` for a constraint only `differential.search` supports.","triggerScenarios":"Conduit `<app>.search` with `\"constraints\": {\"status\": [\"open\"]}` where the engine only knows 'statuses' (singular vs plural), or cross-application keys like using 'repositories' on user.search; also custom engines where a field lacks a Conduit parameter type and thus exposes no valid keys.","commonSituations":"Guessing constraint names from UI labels instead of the Conduit API documentation page (every method documents its exact constraint keys); version drift - constraint renamed across Phabricator releases while scripts kept the old name; singular/plural and camelCase/snake_case mistakes ('authorPHIDs' vs 'authors').","solutions":["Open the method's Conduit documentation (UI: Applications > Conduit > <app>.search) and copy the exact constraint key list; the error names only the first bad key, so check all of them.","Update scripts after Phabricator upgrades - constraint keys occasionally get renamed; keep them in one config spot, not inlined per script.","Remove constraint keys the engine does not support rather than passing empty values as placeholders.","For custom applications, ensure each custom SearchField exposes a Conduit parameter type so its keys become valid."],"exampleFix":"// before\n{\"constraints\": {\"status\": [\"open\"], \"owner\": [\"alice\"]}}\n\n// after\n{\"constraints\": {\"statuses\": [\"open\"], \"ownerPHIDs\": [\"PHID-USER-xxxx\"]}}","handlingStrategy":"validation","validationCode":"// Whitelist against the engine's own field list before sending\n$valid = array();\nforeach ($engine->getSearchFieldsForConduit() as $field) {\n  foreach ($field->getValidConstraintKeys() as $k) { $valid[$k] = true; }\n}\n$constraints = array_intersect_key($constraints, $valid);","typeGuard":"function isValidConstraintKey($engine, $key) { $valid = array(); foreach ($engine->getSearchFieldsForConduit() as $f) { foreach ($f->getValidConstraintKeys() as $k) { $valid[$k] = true; } } return isset($valid[$key]); }","tryCatchPattern":"try {\n  $response = conduct_conduit_call('maniphest.search', $params);\n} catch (Exception $ex) {\n  if (strpos($ex->getMessage(), 'not a valid constraint') !== false) {\n    // strip the named key and retry with remaining constraints\n    unset($params['constraints'][$badKey]);\n  }\n}","preventionTips":["Copy constraint keys from the Conduit method documentation page, not from memory","Centralize constraint names in one constant map per app in your scripts","Re-read docs after upgrading Phabricator - keys get renamed"],"tags":["phabricator","conduit","search","constraints","validation"],"backgroundTag":"unknown-constraint-key","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}