{"record":{"id":"bfa899b7ff553d6e","repo":"dgraph-io/dgraph","slug":"uid-not-found-generated-for-xid-s","errorCode":null,"errorMessage":"UID not found/generated for xid %s\n","messagePattern":"UID not found/generated for xid (.+?)\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dql/mutation.go","lineNumber":109,"sourceCode":"\t\treturn p.Value.([]byte), p.Tid, nil\n\t}\n\n\tp1 := types.ValueForType(types.BinaryID)\n\tif err := types.Marshal(p, &p1); err != nil {\n\t\treturn []byte{}, p.Tid, err\n\t}\n\treturn p1.Value.([]byte), p.Tid, nil\n}\n\nfunc toUid(subject string, newToUid map[string]uint64) (uid uint64, err error) {\n\tif id, err := ParseUid(subject); err == nil || err == errInvalidUID {\n\t\treturn id, err\n\t}\n\t// It's an xid\n\tif id, present := newToUid[subject]; present {\n\t\treturn id, err\n\t}\n\treturn 0, errors.Errorf(\"UID not found/generated for xid %s\\n\", subject)\n}\n\nvar emptyEdge pb.DirectedEdge\n\nfunc (nq NQuad) createEdgePrototype(subjectUid uint64) *pb.DirectedEdge {\n\treturn &pb.DirectedEdge{\n\t\tEntity:    subjectUid,\n\t\tAttr:      nq.Predicate,\n\t\tNamespace: nq.Namespace,\n\t\tLang:      nq.Lang,\n\t\tFacets:    nq.Facets,\n\t}\n}\n\n// CreateUidEdge returns a Directed edge connecting the given subject and object UIDs.\nfunc (nq NQuad) CreateUidEdge(subjectUid uint64, objectUid uint64) *pb.DirectedEdge {\n\tout := nq.createEdgePrototype(subjectUid)\n\tout.ValueId = objectUid","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dql/mutation.go#L91-L127","documentation":"toUid resolves a mutation subject to a UID: it first checks numeric UIDs, then a newToUid map of xids that were assigned UIDs earlier in the same mutation. This error is thrown when the subject is an xid that was neither a known UID nor previously mapped in this mutation, so no UID exists or was generated for it (`UID not found/generated for xid %s`).","triggerScenarios":"Submitting an N-Quad whose subject is an external id (xid, e.g. `\"alice\" <name> \"Alice\" .`) without the `<*> <xid> \"alice\"` edge that tells Dgraph to generate a UID for that xid in the same mutation.","commonSituations":"Bulk-loading data where the xid-declaration edge (`* <xid> *`) was omitted or misspelled, referencing an xid in a later mutation that was only created in an earlier (separate) request, or xid predicate configured differently between runs.","solutions":["Include the xid-declaration N-Quad in the same mutation: `<*> <xid_name> \"alice\" .` so the parser generates/registers a UID for the xid.","Reference the node by its numeric UID (e.g. `<0x123>`) instead of the raw xid if the UID is already known.","Ensure the xid predicate name in the N-Quad exactly matches the configured/schematized xid predicate.","If data was loaded earlier, look up the existing UID first and embed it in subsequent mutations."],"exampleFix":"// before\n{\"set\":[{\"subject\":\"alice\",\"predicate\":\"name\",\"objectValue\":\"Alice\"}]} // xid never declared\n// after\n{\"set\":[{\"subject\":\"*\",\"predicate\":\"xid\",\"objectValue\":\"alice\"},{\"subject\":\"alice\",\"predicate\":\"name\",\"objectValue\":\"Alice\"}]}","handlingStrategy":"validation","validationCode":"func checkXidDeclared(mutations []NQuad, xidPred, xid string) bool {\n    for _, nq := range mutations {\n        if nq.Predicate == xidPred && nq.ObjectValue.GetStringValue() == xid {\n            return true // <*> <xidPred> \"xid\" generates a UID\n        }\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"id, err := toUidWrapper(subject)\nif err != nil && strings.Contains(err.Error(), \"UID not found/generated for xid\") {\n    return fmt.Errorf(\"subject %q is an xid; add '<*> <xid> %q' to the mutation or use a numeric UID\", subject, subject)\n}","preventionTips":["Always include the `<*> <xid> \"value\" .` edge in the same mutation when subjects are xids.","Prefer numeric UIDs (0x...) for nodes that already exist.","Keep the xid predicate name consistent with schema across all writers."],"tags":["dgraph","mutation","xid"],"backgroundTag":"xid-not-mapped-to-uid","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}