{"record":{"id":"1187d0b5d628a2bf","repo":"dgraph-io/dgraph","slug":"expected-2-child-for-not-but-got-d","errorCode":null,"errorMessage":"Expected 2 child for not but got %d.","messagePattern":"Expected 2 child for not but got (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2487,"sourceCode":"\t}\n\n\tfor _, c := range tree.Children {\n\t\tftreec, err := preprocessFilter(c)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tftree.children = append(ftree.children, ftreec)\n\t}\n\n\tnumChild := len(tree.Children)\n\tswitch ftree.op {\n\tcase \"not\":\n\t\tif numChild != 1 {\n\t\t\treturn nil, errors.Errorf(\"Expected 1 child for not but got %d.\", numChild)\n\t\t}\n\tcase \"and\":\n\t\tif numChild != 2 {\n\t\t\treturn nil, errors.Errorf(\"Expected 2 child for not but got %d.\", numChild)\n\t\t}\n\tcase \"or\":\n\t\tif numChild != 2 {\n\t\t\treturn nil, errors.Errorf(\"Expected 2 child for not but got %d.\", numChild)\n\t\t}\n\tdefault:\n\t\treturn nil, errors.Errorf(\"Unsupported operation in facet filtering: %s.\", tree.Op)\n\t}\n\treturn ftree, nil\n}\n\ntype countParams struct {\n\treadTs  uint64\n\tcounts  []int64\n\tattr    string\n\tgid     uint32\n\treverse bool   // If query is asking for ~pred\n\tfn      string // function name","sourceCodeStart":2469,"sourceCodeEnd":2505,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2469-L2505","documentation":"The `and` branch of the facet filter arity check requires exactly two children. The message text mistakenly says \"for not\" (a known copy-paste quirk in the message string), but the failure is an AND node with child count other than 2.","triggerScenarios":"An AND facet filter with one or three-plus operands, e.g. @facets(eq(a,\"1\") AND eq(b,\"2\") AND eq(c,\"3\")) built as a flat 3-child AND.","commonSituations":"Writing multi-term AND facet filters expecting n-ary support; query builders emitting n-ary AND nodes.","solutions":["Limit each AND to two operands and nest the rest: (a AND b) AND c.","Recheck the query's boolean tree shape; the confusing message still points to an arity problem on an `and` node.","Ensure generated queries produce binary AND nodes."],"exampleFix":"// before\n@facets(eq(a,\"1\") AND eq(b,\"2\") AND eq(c,\"3\"))\n// after\n@facets((eq(a,\"1\") AND eq(b,\"2\")) AND eq(c,\"3\"))","handlingStrategy":"validation","validationCode":"function validateAndArity(tree) {\n  if (tree.op === \"and\" && tree.children.length !== 2)\n    throw new Error(\"and must have exactly 2 children in facet filter\");\n  (tree.children || []).forEach(validateAndArity);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await txn.query(query);\n} catch (e) {\n  if (/Expected 2 child/.test(String(e))) {\n    // binarize AND/OR nodes and retry\n  }\n  throw e;\n}","preventionTips":["Emit binary (two-child) AND nodes in query builders.","Nest extra conjuncts: (a AND b) AND c.","Remember this Dgraph version's misleading message says \"for not\" even for and/or."],"tags":["dgraph","query","facets","boolean-logic"],"backgroundTag":"invalid-filter-arity","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}