{"record":{"id":"93aec04ca8e795db","repo":"dgraph-io/dgraph","slug":"argument-cannot-be-uid","errorCode":null,"errorMessage":"Argument cannot be \"uid\"","messagePattern":"Argument cannot be \"uid\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":475,"sourceCode":"\nfunc filterCopy(sg *SubGraph, ft *dql.FilterTree) error {\n\t// Either we'll have an operation specified, or the function specified.\n\tif len(ft.Op) > 0 {\n\t\tsg.FilterOp = ft.Op\n\t} else {\n\t\tsg.Attr = ft.Func.Attr\n\t\tif !isValidFuncName(ft.Func.Name) {\n\t\t\treturn errors.Errorf(\"Invalid function name: %s\", ft.Func.Name)\n\t\t}\n\n\t\tif isUidFnWithoutVar(ft.Func) {\n\t\t\tsg.SrcFunc = &Function{Name: ft.Func.Name}\n\t\t\tif err := sg.populate(ft.Func.UID); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t} else {\n\t\t\tif ft.Func.Attr == \"uid\" {\n\t\t\t\treturn errors.Errorf(`Argument cannot be \"uid\"`)\n\t\t\t}\n\t\t\tsg.createSrcFunction(ft.Func)\n\t\t\tsg.Params.NeedsVar = append(sg.Params.NeedsVar, ft.Func.NeedsVar...)\n\t\t}\n\t}\n\tfor _, ftc := range ft.Child {\n\t\tchild := &SubGraph{}\n\t\tif err := filterCopy(child, ftc); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tsg.Filters = append(sg.Filters, child)\n\t}\n\treturn nil\n}\n\nfunc uniqueKey(gchild *dql.GraphQuery) string {\n\tkey := gchild.Attr\n\tif gchild.Func != nil {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L457-L493","documentation":"In filterCopy, a non-uid filter function whose attribute is literally \"uid\" is rejected: uid is a reserved node identifier and cannot be used as an argument/attribute for regular filter functions. The check prevents building a sub-graph function over the special uid attribute.","triggerScenarios":"A filter like `@filter(eq(uid, \"0x1\"))` or any <fn>(uid, ...) other than the dedicated uid() function path (isUidFnWithoutVar already handled the uid function case).","commonSituations":"Users trying to filter by node UID with a generic comparison function instead of the uid() function or func: uid(...).","solutions":["Use the uid() function form: @filter(uid(0x1, 0x2)) or func: uid(0x1)","Fetch nodes by UID directly with func: uid(...) at root instead of filtering on uid","Filter on a scalar indexed predicate instead of uid"],"exampleFix":"// before\n{ q(func: type(Person)) @filter(eq(uid, \"0x1\")) { uid } }\n// after\n{ q(func: uid(0x1)) { uid name } }","handlingStrategy":"validation","validationCode":"// Go: reject non-uid functions over the uid attribute before sending\nif fn.Attr == \"uid\" && fn.Name != \"uid\" {\n    return errors.New(\"use the uid() function or func: uid(...) instead of filtering on uid\")\n}","typeGuard":"func filterAttrIsValid(fn FilterFunc) bool {\n    return fn.Attr != \"uid\" || fn.Name == \"uid\"\n}","tryCatchPattern":"_, err := txn.Query(ctx, dql)\nif err != nil && strings.Contains(err.Error(), \"Argument cannot be\") {\n    return errors.New(\"rewrite filter to use func: uid(<ids>) or @filter(uid(<ids>))\")\n}","preventionTips":["Always fetch/filter UIDs via func: uid(...) or @filter(uid(...))","Never use uid as an attribute argument to eq/lt/etc.","Build UIDs into the root function rather than filters"],"tags":["dgraph","dql","filter","uid","reserved-argument"],"backgroundTag":"invalid-dql-function-name","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}