{"record":{"id":"fbce83144d7af614","repo":"dgraph-io/dgraph","slug":"expected-1-child-for-not-but-got-d","errorCode":null,"errorMessage":"Expected 1 child for not but got %d.","messagePattern":"Expected 1 child for not but got (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":2483,"sourceCode":"\t\tdefault:\n\t\t\treturn nil, errors.Errorf(\"Fn %s not supported in preprocessFilter.\", fname)\n\t\t}\n\t\treturn ftree, nil\n\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","sourceCodeStart":2465,"sourceCodeEnd":2501,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L2465-L2501","documentation":"The facet filter tree builder validates boolean operator arity: a `not` node must have exactly one child. Receiving 0 or 2+ children under a not means the parsed query's boolean structure is malformed for facets.","triggerScenarios":"A query like @facets(not(a AND b)) constructed so `not` wraps multiple children, or an empty/invalid not expression reaching preprocessFilter.","commonSituations":"Hand-written queries with ambiguous nesting; generated queries from ORMs/tools that mis-parenthesize NOT; converting SQL NOT IN patterns to Dgraph facet syntax.","solutions":["Give `not` exactly one operand: @facets(not(eq(name, \"x\"))).","Wrap a multi-condition negation in parentheses: @facets(not((eq(a,\"1\") OR eq(b,\"2\")))).","Check the query generator's parenthesis emission for NOT."],"exampleFix":"// before\n@facets(not(eq(a, \"1\") AND eq(b, \"2\")))\n// after\n@facets(not((eq(a, \"1\") AND eq(b, \"2\"))))","handlingStrategy":"validation","validationCode":"function validateNotArity(tree) {\n  if (tree.op === \"not\" && tree.children.length !== 1)\n    throw new Error(\"not must have exactly 1 child in facet filter\");\n  (tree.children || []).forEach(validateNotArity);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await txn.query(query);\n} catch (e) {\n  if (/Expected 1 child for not/.test(String(e))) {\n    // fix boolean nesting in the query generator\n  }\n  throw e;\n}","preventionTips":["Always wrap multi-operand negations in parentheses.","Ensure NOT nodes in query builders emit exactly one child.","Add AST-arity unit tests for NOT in generated queries."],"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"}