dgraph-io/dgraph · error

Argument cannot be "uid"

Error message

Argument cannot be "uid"

What it means

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.

Source

Thrown at query/query.go:475

func filterCopy(sg *SubGraph, ft *dql.FilterTree) error {
	// Either we'll have an operation specified, or the function specified.
	if len(ft.Op) > 0 {
		sg.FilterOp = ft.Op
	} else {
		sg.Attr = ft.Func.Attr
		if !isValidFuncName(ft.Func.Name) {
			return errors.Errorf("Invalid function name: %s", ft.Func.Name)
		}

		if isUidFnWithoutVar(ft.Func) {
			sg.SrcFunc = &Function{Name: ft.Func.Name}
			if err := sg.populate(ft.Func.UID); err != nil {
				return err
			}
		} else {
			if ft.Func.Attr == "uid" {
				return errors.Errorf(`Argument cannot be "uid"`)
			}
			sg.createSrcFunction(ft.Func)
			sg.Params.NeedsVar = append(sg.Params.NeedsVar, ft.Func.NeedsVar...)
		}
	}
	for _, ftc := range ft.Child {
		child := &SubGraph{}
		if err := filterCopy(child, ftc); err != nil {
			return err
		}
		sg.Filters = append(sg.Filters, child)
	}
	return nil
}

func uniqueKey(gchild *dql.GraphQuery) string {
	key := gchild.Attr
	if gchild.Func != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use the uid() function form: @filter(uid(0x1, 0x2)) or func: uid(0x1)
  2. Fetch nodes by UID directly with func: uid(...) at root instead of filtering on uid
  3. Filter on a scalar indexed predicate instead of uid

Example fix

// before
{ q(func: type(Person)) @filter(eq(uid, "0x1")) { uid } }
// after
{ q(func: uid(0x1)) { uid name } }
Defensive patterns

Strategy: validation

Validate before calling

// Go: reject non-uid functions over the uid attribute before sending
if fn.Attr == "uid" && fn.Name != "uid" {
    return errors.New("use the uid() function or func: uid(...) instead of filtering on uid")
}

Type guard

func filterAttrIsValid(fn FilterFunc) bool {
    return fn.Attr != "uid" || fn.Name == "uid"
}

Try / catch

_, err := txn.Query(ctx, dql)
if err != nil && strings.Contains(err.Error(), "Argument cannot be") {
    return errors.New("rewrite filter to use func: uid(<ids>) or @filter(uid(<ids>))")
}

Prevention

When it happens

Trigger: 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).

Common situations: Users trying to filter by node UID with a generic comparison function instead of the uid() function or func: uid(...).

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/93aec04ca8e795db. Report an issue: GitHub.