dgraph-io/dgraph · error
Attribute not scalar: %s %v
Error message
Attribute not scalar: %s %v
What it means
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.
Source
Thrown at worker/task.go:1256
}
func (qs *queryState) handleRegexFunction(ctx context.Context, arg funcArgs) error {
span := trace.SpanFromContext(ctx)
stop := x.SpanTimer(span, "handleRegexFunction")
defer stop()
if span != nil {
span.AddEvent("Processing UIDs", trace.WithAttributes(
attribute.Int64("uid_count", int64(arg.srcFn.n)),
attribute.String("srcFn", x.SafeUTF8(fmt.Sprintf("%+v", arg.srcFn)))))
}
attr := arg.q.Attr
typ, err := schema.State().TypeOf(attr)
span.AddEvent("Attribute information", trace.WithAttributes(
attribute.String("attr", attr),
attribute.String("type", typ.Name())))
if err != nil || !typ.IsScalar() {
return errors.Errorf("Attribute not scalar: %s %v", x.ParseAttr(attr), typ)
}
if typ != types.StringID {
return errors.Errorf("Got non-string type. Regex match is allowed only on string type.")
}
useIndex := schema.State().HasTokenizer(ctx, tok.IdentTrigram, attr)
span.AddEvent("Trigram index information", trace.WithAttributes(
attribute.Bool("trigram_index_found", useIndex),
attribute.Bool("func_at_root", arg.srcFn.isFuncAtRoot)))
query := cindex.RegexpQuery(arg.srcFn.regex.Syntax)
empty := pb.List{}
var uids *pb.List
// Here we determine the list of uids to match.
switch {
// If this is a filter eval, use the given uid list (good)
case arg.q.UidList != nil:
// These UIDs are copied into arg.out.UidMatrix which is later updated whileView on GitHub (pinned to 759e242be6)
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
Example fix
// before (regex on uid edge)
friend: [uid] .
query { q(func: regexp(friend, /x/)) }
// after
name: string @index(trigram) .
query { q(func: regexp(name, /x/)) } Defensive patterns
Strategy: validation
Validate before calling
schema, _ := client.Query(ctx, `schema(pred: [name]) {}`)
// regexp requires a scalar string predicate; reject uid edges early
if strings.Contains(schema.String(), "uid") {
return errors.New("regexp not allowed on uid predicate")
} Try / catch
resp, err := client.Query(ctx, q)
if err != nil && strings.Contains(err.Error(), "Attribute not scalar") {
glog.Errorf("predicate is a uid edge or missing; fix schema/predicate name")
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to get schema: %v
- Fail to convert from api.Value to types.Val
- error querying graphql schema
- Predicate %s is not indexed
- Need @count directive in schema for attr: %s for fn: %s at r
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/9f3035fbbbc6c657.
Report an issue: GitHub.