{"record":{"id":"553e76f1f4891bea","repo":"dgraph-io/dgraph","slug":"node-with-q-cant-have-child-attr","errorCode":null,"errorMessage":"Node with %q cant have child attr","messagePattern":"Node with %q cant have child attr","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":622,"sourceCode":"\t\t\treturn errors.Errorf(\"Cannot specify order at both args and facets\")\n\t\t}\n\n\t\tdst := &SubGraph{\n\t\t\tAttr:   gchild.Attr,\n\t\t\tParams: args,\n\t\t}\n\t\tif gchild.MathExp != nil {\n\t\t\tmathExp := &mathTree{}\n\t\t\tif err := mathCopy(mathExp, gchild.MathExp); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tdst.MathExp = mathExp\n\t\t}\n\n\t\tif gchild.Func != nil &&\n\t\t\t(gchild.Func.IsAggregator() || gchild.Func.IsPasswordVerifier()) {\n\t\t\tif len(gchild.Children) != 0 {\n\t\t\t\treturn errors.Errorf(\"Node with %q cant have child attr\", gchild.Func.Name)\n\t\t\t}\n\t\t\t// embedded filter will cause ambiguous output like following,\n\t\t\t// director.film @filter(gt(initial_release_date, \"2016\")) {\n\t\t\t//    min(initial_release_date @filter(gt(initial_release_date, \"1986\"))\n\t\t\t// }\n\t\t\tif gchild.Filter != nil {\n\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\"Node with %q cant have filter, please place the filter on the upper level\",\n\t\t\t\t\tgchild.Func.Name)\n\t\t\t}\n\t\t\tif gchild.Func.Attr == \"uid\" {\n\t\t\t\treturn errors.Errorf(`Argument cannot be \"uid\"`)\n\t\t\t}\n\t\t\tdst.createSrcFunction(gchild.Func)\n\t\t}\n\n\t\tif gchild.Filter != nil {\n\t\t\tdstf := &SubGraph{}","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L604-L640","documentation":"Aggregator functions (min, max, sum, avg, count) and password verifiers produce a single scalar value per node, so the node carrying such a function cannot have child attributes. treeCopy rejects any gchild whose Func.IsAggregator() or IsPasswordVerifier() and also has children. Children under an aggregate node have no meaningful output location.","triggerScenarios":"Writing `min(friend) { name }` or `checkpwd(password) { ... }` with a brace block; query builders that always emit children for every field.","commonSituations":"Users trying to compute an aggregate of child values and also read child data in one node; misunderstanding that min(parent) aggregates the parent's child values, not a subtree query.","solutions":["Make the aggregate node a leaf: `min(friend)` or place the aggregate on a scalar predicate like `min(score)`","Fetch child details in a sibling level, e.g. `friend { name }` alongside `min(...) as ...`","For per-child aggregation, put the aggregator one level down on the scalar predicate: `friend { min(score) }`"],"exampleFix":"// before\n{\n  me(func: uid(0x1)) {\n    min(friend) {\n      name\n    }\n  }\n}\n// after\n{\n  me(func: uid(0x1)) {\n    friend {\n      name\n    min as min(score)\n    }\n  }\n}","handlingStrategy":"validation","validationCode":"function assertAggregateIsLeaf(node) {\n  if (/^(min|max|sum|avg|count)\\s*\\(/.test(node.field) && node.children && node.children.length > 0) {\n    throw new Error('Aggregator node cannot have child attributes');\n  }\n}","typeGuard":"const isAggregateWithChildren = (n) => n.func && ['min','max','sum','avg','count','checkpwd'].includes(n.func.name) && n.children && n.children.length > 0;","tryCatchPattern":"try {\n  await txn.query(q);\n} catch (e) {\n  if (e.message.includes('cant have child attr')) {\n    throw new Error('Make the aggregate node a leaf; fetch details in a sibling level');\n  }\n  throw e;\n}","preventionTips":["Always render aggregates as leaf nodes","Place per-child aggregates one level down on scalar predicates","Builders: suppress children when an aggregator wraps the field"],"tags":["dgraph","query","aggregation","validation"],"backgroundTag":"invalid-query-argument","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}