{"record":{"id":"d68fae4e1a57e684","repo":"dgraph-io/dgraph","slug":"input-for-predicate-q-of-type-scalar-is-uid-edge","errorCode":null,"errorMessage":"Input for predicate %q of type scalar is uid. Edge: %v","messagePattern":"Input for predicate %q of type scalar is uid\\. Edge: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":537,"sourceCode":"\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.\n\tcase schemaType == types.DefaultID:\n\t\tschemaType = storageType\n\t}\n","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L519-L555","documentation":"Mirror case of the scalar-for-uid error: the predicate's schema type is a scalar, but the mutation's storage value is a uid (node reference). ValidateAndConvert rejects the edge because a scalar predicate cannot hold node references.","triggerScenarios":"Running a mutation that assigns a node (UID edge) to a predicate declared as a scalar type, e.g. `<0x1> <age> <0x2> .` where age is `int`, or listing a UID where the schema says string/float.","commonSituations":"Swapping subject/object in hand-written N-Quads; generating mutations programmatically and passing object UIDs into attribute predicates; schema changed to scalar after UIDs were already being written.","solutions":["Write a literal value matching the schema type, e.g. `<0x1> <age> \"30\"^^<xs:int> .`.","If the relationship is real, change the schema to `age: [uid]` instead.","Inspect the failing edge in the error message to see which side of the triple is wrong."],"exampleFix":"// before (fails; age is int)\n<0x1> <age> <0x2> .\n\n// after\n<0x1> <age> \"30\"^^<xs:int> .","handlingStrategy":"type-guard","validationCode":"function assertScalarObject(triple, scalarType) {\n  const isUidRef = typeof triple.object === 'object' && triple.object !== null && 'uid' in triple.object\n  if (scalarType !== 'uid' && isUidRef) {\n    throw new Error(`predicate ${triple.predicate} is ${scalarType}; object must be a literal`)\n  }\n}","typeGuard":"function isLiteral(v) {\n  return typeof v !== 'object' || v === null || !('uid' in v)\n}","tryCatchPattern":"try {\n  await txn.mutate(mu)\n} catch (e) {\n  if (String(e).includes('of type scalar is uid')) {\n    // either write a literal of the schema type, or change the schema to uid\n  }\n}","preventionTips":["Map predicates to value types explicitly in your mutation builder.","Watch for swapped subject/object in hand-written N-Quads.","Re-generate clients after schema type changes (uid <-> scalar)."],"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"}