{"record":{"id":"aac0730bccc55a6a","repo":"dgraph-io/dgraph","slug":"failure-to-convert-edge-type-v-to-schema-type","errorCode":null,"errorMessage":"failure to convert edge type: '%+v' to schema type: '%+v'","messagePattern":"failure to convert edge type: '%\\+v' to schema type: '%\\+v'","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":591,"sourceCode":"\n\tif x.WorkerConfig.AclEnabled && x.ParseAttr(edge.GetAttr()) == \"dgraph.rule.permission\" {\n\t\tperm, ok := dst.Value.(int64)\n\t\tif !ok {\n\t\t\treturn errors.Errorf(\"Value for predicate <dgraph.rule.permission> should be of type int\")\n\t\t}\n\t\tif perm < 0 || perm > 7 {\n\t\t\treturn errors.Errorf(\"Can't set <dgraph.rule.permission> to %d, Value for this\"+\n\t\t\t\t\" predicate should be between 0 and 7\", perm)\n\t\t}\n\t}\n\n\t// TODO: Figure out why this is Enum. It really seems like an odd choice -- rather than\n\t//       specifying it as the same type as presented in su.\n\tedge.ValueType = schemaType.Enum()\n\tvar ok bool\n\tedge.Value, ok = b.Value.([]byte)\n\tif !ok {\n\t\treturn errors.Errorf(\"failure to convert edge type: '%+v' to schema type: '%+v'\",\n\t\t\tstorageType, schemaType)\n\t}\n\n\treturn nil\n}\n\n// AssignNsIdsOverNetwork sends a request to assign Namespace IDs to the current zero leader.\nfunc AssignNsIdsOverNetwork(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {\n\th := hooks.GetHooks()\n\tnum.Type = pb.Num_NS_ID\n\treturn h.AssignNsIDs(ctx, num)\n}\n\n// AssignUidsOverNetwork sends a request to assign UIDs from the current zero leader.\nfunc AssignUidsOverNetwork(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {\n\th := hooks.GetHooks()\n\tnum.Type = pb.Num_UID\n\treturn h.AssignUIDs(ctx, num)","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L573-L609","documentation":"This error is thrown by ValidateAndConvert in worker/mutation.go when, after a value has been successfully converted and marshalled to the schema type, the resulting binary value cannot be asserted to a []byte. It signals an internal failure in the type-conversion pipeline: the marshalled value for the edge does not carry the expected binary payload, so the edge cannot be stored with the requested schema type. The message reports both the storage type found on the edge and the schema type the predicate declares.","triggerScenarios":"A mutation passes a value for a predicate whose schema-declared type requires conversion (storageType != schemaType, e.g. default string to datetime, or int to float). types.Convert succeeds and types.Marshal produces a types.Value whose Value field is not actually a []byte (unexpected marshaler output for that type), so the assertion b.Value.([]byte) fails at worker/mutation.go:589-592.","commonSituations":"Migrating predicates between scalar types (e.g. changing a predicate from string to datetime in the schema) and repushing old data; JSON/RDF mutations where the incoming literal type differs from the schema type; bugs or version mismatches in the types package where a marshaler returns a non-binary value; corrupt or hand-crafted postings where edge.ValueType disagrees with the actual value encoding.","solutions":["Verify the value in the mutation actually matches the schema type for the predicate (run a query or check dgraph schema output) and resend the mutation with the correct literal (e.g. quoted \"2020-01-01\" for datetime)","If the schema type was recently changed, either delete and re-write the affected predicates or run data migration so stored values conform to the new type","Upgrade to the latest Dgraph version; non-[]byte marshal output is usually an internal bug in types.Convert/types.Marshal that may be fixed upstream","Reproduce with the failing edge value and file an issue with the storageType/schemaType values printed in the error, since reaching this path means Convert already succeeded"],"exampleFix":"// before (mutation sends plain string for a datetime predicate)\n{\"set\":[{\"uid\":\"0x1\",\"created\":\"1693556000\"}]}\n\n// after (send value in the schema-declared format)\n{\"set\":[{\"uid\":\"0x1\",\"created\":\"2023-09-01T07:33:20Z\"}]}","handlingStrategy":"validation","validationCode":"// Check the value's type against the schema type before mutating\nschema, _ := client.Query(context.Background(), `schema(pred: [created]) {}`)\n// ensure literal format matches the declared schema type, e.g. datetime:\n// value must parse as RFC3339 before being sent\nfunc isValidRFC3339(s string) bool {\n\t_, err := time.Parse(time.RFC3339, s)\n\treturn err == nil\n}","typeGuard":null,"tryCatchPattern":"// Go client\nresp, err := txn.Mutate(ctx, mu)\nif err != nil {\n\tif strings.Contains(err.Error(), \"failure to convert edge type\") {\n\t\t// value does not conform to schema type: fix the literal and retry\n\t\treturn fmt.Errorf(\"mutation value incompatible with schema type: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Always query the schema (dgraph schema) and match literal formats to declared predicate types","When changing a predicate's type in the schema, migrate or rewrite existing data","Quote values whose types are ambiguous in RDF (e.g. \"2020-01-01\"^^xs:dateTime)","Keep Dgraph server and client versions aligned to avoid types-package conversion bugs"],"tags":["type-conversion","schema","dgraph","mutation"],"backgroundTag":"type-conversion-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}