dgraph-io/dgraph · error
ObjectId should be > 0 for nquad: %+v
Error message
ObjectId should be > 0 for nquad: %+v
What it means
In ToEdgeUsing, when the N-Quad's object is a UID-valued edge (x.ValueUid), the object is resolved with toUid; if the resulting object UID is 0 the edge would point at nothing, so the library returns this error. Only UID-typed objects take this path; literal-valued objects go through CreateValueEdge and are validated elsewhere.
Source
Thrown at dql/mutation.go:188
func (nq NQuad) ToEdgeUsing(newToUid map[string]uint64) (*pb.DirectedEdge, error) {
var edge *pb.DirectedEdge
sUid, err := toUid(nq.Subject, newToUid)
if err != nil {
return nil, err
}
if sUid == 0 {
return nil, errors.Errorf("Subject should be > 0 for nquad: %+v", nq)
}
switch nq.valueType() {
case x.ValueUid:
oUid, err := toUid(nq.ObjectId, newToUid)
if err != nil {
return nil, err
}
if oUid == 0 {
return nil, errors.Errorf("ObjectId should be > 0 for nquad: %+v", nq)
}
edge = nq.CreateUidEdge(sUid, oUid)
case x.ValuePlain, x.ValueMulti:
edge, err = nq.CreateValueEdge(sUid)
default:
return &emptyEdge, errors.Errorf("Unknown value type for nquad: %+v", nq)
}
if err != nil {
return nil, err
}
return edge, nil
}
func copyValue(out *pb.DirectedEdge, nq NQuad) error {
var err error
var t types.TypeID
if out.Value, t, err = byteVal(nq); err != nil {
return errView on GitHub (pinned to 759e242be6)
Solutions
- Verify the object blank-node label matches exactly (including case) the label used where the node is created in newToUid
- Pre-assign UIDs for every referenced node (e.g. via upsert blocks or a first mutation pass) before building edges to them
- Confirm explicit object UIDs are non-zero and correspond to existing nodes
- Inspect the nquad in the error message to identify the failing object value
Example fix
// before
toUid := map[string]uint64{"_:alice": 0x1001} // _:bob missing
// after
toUid := map[string]uint64{"_:alice": 0x1001, "_:bob": 0x1002} Defensive patterns
Strategy: validation
Validate before calling
func validObject(nq *api.NQuad, toUid map[string]uint64) bool {
if nq.ObjectId == "" { return nq.ObjectValue != nil }
if uid, err := strconv.ParseUint(nq.ObjectId, 0, 64); err == nil { return uid != 0 }
if strings.HasPrefix(nq.ObjectId, "_:") { return toUid[nq.ObjectId] != 0 }
return false
} Prevention
- Assign UIDs to all referenced nodes before creating edges to them
- Use upsert blocks or a two-pass mutation for blank-node references
- Match blank-node labels exactly between subject and object positions
When it happens
Trigger: Calling ToEdgeUsing with an N-Quad whose object is a UID reference (another node or blank node) that resolves to 0 — e.g. a blank node _:bob absent from the newToUid map, or an explicit object UID of 0.
Common situations: Typos in blank-node labels between subject and object positions of quads; mutations referencing nodes that were never upserted/allocated; copying example code that uses UIDs that don't exist in your graph.
Related errors
- Subject should be > 0 for nquad: %+v
- Unknown value type for nquad: %+v
- Invalid Math expression
- Invalid math statement. Expected 1 operands
- Division by zero
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/d91ab8efe4488eb1.
Report an issue: GitHub.