{"record":{"id":"9f3035fbbbc6c657","repo":"dgraph-io/dgraph","slug":"attribute-not-scalar-s-v","errorCode":null,"errorMessage":"Attribute not scalar: %s %v","messagePattern":"Attribute not scalar: (.+?) (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":1256,"sourceCode":"}\n\nfunc (qs *queryState) handleRegexFunction(ctx context.Context, arg funcArgs) error {\n\tspan := trace.SpanFromContext(ctx)\n\tstop := x.SpanTimer(span, \"handleRegexFunction\")\n\tdefer stop()\n\tif span != nil {\n\t\tspan.AddEvent(\"Processing UIDs\", trace.WithAttributes(\n\t\t\tattribute.Int64(\"uid_count\", int64(arg.srcFn.n)),\n\t\t\tattribute.String(\"srcFn\", x.SafeUTF8(fmt.Sprintf(\"%+v\", arg.srcFn)))))\n\t}\n\n\tattr := arg.q.Attr\n\ttyp, err := schema.State().TypeOf(attr)\n\tspan.AddEvent(\"Attribute information\", trace.WithAttributes(\n\t\tattribute.String(\"attr\", attr),\n\t\tattribute.String(\"type\", typ.Name())))\n\tif err != nil || !typ.IsScalar() {\n\t\treturn errors.Errorf(\"Attribute not scalar: %s %v\", x.ParseAttr(attr), typ)\n\t}\n\tif typ != types.StringID {\n\t\treturn errors.Errorf(\"Got non-string type. Regex match is allowed only on string type.\")\n\t}\n\tuseIndex := schema.State().HasTokenizer(ctx, tok.IdentTrigram, attr)\n\tspan.AddEvent(\"Trigram index information\", trace.WithAttributes(\n\t\tattribute.Bool(\"trigram_index_found\", useIndex),\n\t\tattribute.Bool(\"func_at_root\", arg.srcFn.isFuncAtRoot)))\n\n\tquery := cindex.RegexpQuery(arg.srcFn.regex.Syntax)\n\tempty := pb.List{}\n\tvar uids *pb.List\n\n\t// Here we determine the list of uids to match.\n\tswitch {\n\t// If this is a filter eval, use the given uid list (good)\n\tcase arg.q.UidList != nil:\n\t\t// These UIDs are copied into arg.out.UidMatrix which is later updated while","sourceCodeStart":1238,"sourceCodeEnd":1274,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L1238-L1274","documentation":"handleRegexFunction (regexp matching) only works on scalar attributes. If the predicate type lookup fails or the type is not scalar (e.g. it's a UID/edge predicate), this error is returned with the type in the message.","triggerScenarios":"Running a query with `regexp(...)` against a predicate that is a uid edge (`[uid]`) or whose schema type cannot be resolved; typo in predicate name so TypeOf fails.","commonSituations":"Applying regex to an edge predicate by mistake; querying a predicate that doesn't exist (schema miss); copy-pasted queries referencing another project's schema.","solutions":["Verify the predicate is scalar with `schema(pred: [name]) {}` and correct the predicate name if it's a uid edge","Use a value predicate typed `string` for regex matching","If regex is needed on edges, restructure the data model (add a scalar attribute)","Check for typos in the predicate name in the regexp filter"],"exampleFix":"// before (regex on uid edge)\nfriend: [uid] .\nquery { q(func: regexp(friend, /x/)) }\n// after\nname: string @index(trigram) .\nquery { q(func: regexp(name, /x/)) }","handlingStrategy":"validation","validationCode":"schema, _ := client.Query(ctx, `schema(pred: [name]) {}`)\n// regexp requires a scalar string predicate; reject uid edges early\nif strings.Contains(schema.String(), \"uid\") {\n    return errors.New(\"regexp not allowed on uid predicate\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Query(ctx, q)\nif err != nil && strings.Contains(err.Error(), \"Attribute not scalar\") {\n    glog.Errorf(\"predicate is a uid edge or missing; fix schema/predicate name\")\n    return err\n}","preventionTips":["Check `schema {}` output to confirm the predicate type before using regexp","Reserve regexp for string predicates; use uid-based queries for edges","Validate predicate names against the schema in application tests"],"tags":["query","schema","regex","type-check"],"backgroundTag":"predicate-not-scalar","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}