{"record":{"id":"fff468b55e1ef745","repo":"dgraph-io/dgraph","slug":"input-for-predicate-q-of-type-uid-is-scalar-edge","errorCode":null,"errorMessage":"Input for predicate %q of type uid is scalar. Edge: %v","messagePattern":"Input for predicate %q of type uid is scalar\\. Edge: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":533,"sourceCode":"\n\tif strings.Contains(su.Predicate, hnsw.VecKeyword) {\n\t\treturn errors.Errorf(\"Not allowed to insert mutations in vector index keys, edge: [%v]\", edge)\n\t}\n\n\tstorageType := posting.TypeID(edge)\n\tschemaType := types.TypeID(su.ValueType)\n\n\t// type checks\n\tswitch {\n\tcase edge.Lang != \"\" && !su.GetLang():\n\t\treturn errors.Errorf(\"Attr: [%v] should have @lang directive in schema to mutate edge: [%v]\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase !schemaType.IsScalar() && !storageType.IsScalar():\n\t\treturn nil\n\n\tcase !schemaType.IsScalar() && storageType.IsScalar():\n\t\treturn errors.Errorf(\"Input for predicate %q of type uid is scalar. Edge: %v\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase schemaType.IsScalar() && !storageType.IsScalar():\n\t\treturn errors.Errorf(\"Input for predicate %q of type scalar is uid. Edge: %v\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase schemaType == types.TypeID(pb.Posting_VFLOAT):\n\t\tif !(storageType == types.TypeID(pb.Posting_VFLOAT) || storageType == types.TypeID(pb.Posting_STRING) ||\n\t\t\tstorageType == types.TypeID(pb.Posting_DEFAULT)) {\n\t\t\treturn errors.Errorf(\"Input for predicate %q of type vector is not vector.\"+\n\t\t\t\t\" Did you forget to add quotes before []?. Edge: %v\", x.ParseAttr(edge.Attr), edge)\n\t\t}\n\n\t// The suggested storage type matches the schema, OK! (Nothing to do ...)\n\tcase storageType == schemaType && schemaType != types.DefaultID:\n\t\treturn nil\n\n\t// We accept the storage type iff we don't have a schema type and a storage type is specified.","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L515-L551","documentation":"The predicate's schema type is uid (a non-scalar/edge type), but the incoming mutation carries a scalar storage value (a literal, not a UID reference). ValidateAndConvert rejects this mismatch because a uid predicate can only be assigned node references.","triggerScenarios":"Running a mutation that assigns a literal value (string, number, default-typed value) to a predicate declared as `uid` in the schema, e.g. `<0x1> <friend> \"alice\" .` where friend is `friend: [uid]`.","commonSituations":"Using blank node or string identifiers without converting them to UIDs (e.g. via upsert or the <uid> placeholder in DQL); copy-pasted RDF that treats edges like attributes; client libraries serializing values as strings instead of UIDs.","solutions":["Mutate with an actual UID reference, e.g. `<0x1> <friend> <0x2> .` or use `<friend> * * .` expansions correctly.","Use an upsert block with uid() to resolve identifiers to UIDs before linking: `upsert { query { f as var(func: eq(name, \"alice\")) } mutation { set { <0x1> <friend> uid(f) . } } }`.","Fix the schema to a scalar type if the value is really an attribute, not a relationship."],"exampleFix":"// before (fails; friend is uid)\n<0x1> <friend> \"alice\" .\n\n// after (upsert resolves name to uid)\nupsert { query { f as var(func: eq(name, \"alice\")) }\n  mutation { set { <0x1> <friend> uid(f) . } } }","handlingStrategy":"type-guard","validationCode":"function assertUidObject(triple) {\n  if (triple.predicateType === 'uid' && !/^<0x[0-9a-f]+>$|^_:[a-zA-Z0-9_]+$/.test(triple.object)) {\n    throw new Error(`object must be a uid for ${triple.predicate}; got ${triple.object}`)\n  }\n}","typeGuard":"function isUidRef(v) {\n  return typeof v === 'object' && v !== null &&\n    (typeof v.uid === 'string' || typeof v.uid === 'number')\n}","tryCatchPattern":"try {\n  await txn.mutate(mu)\n} catch (e) {\n  if (String(e).includes('of type uid is scalar')) {\n    // resolve identifier to a UID (upsert/uid()) and re-mutate\n  }\n}","preventionTips":["For uid predicates, always send node references, blank nodes, or uid() expressions — never literals.","Use upsert blocks with eq() lookups to map external IDs to UIDs.","Check the schema (schema{}) before generating mutations so types are known."],"tags":["dgraph","mutation","type-mismatch","uid"],"backgroundTag":"type-mismatch-mutation","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}