dgraph-io/dgraph · error
failure to convert edge type: '%+v' to schema type: '%+v'
Error message
failure to convert edge type: '%+v' to schema type: '%+v'
What it means
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.
Source
Thrown at worker/mutation.go:591
if x.WorkerConfig.AclEnabled && x.ParseAttr(edge.GetAttr()) == "dgraph.rule.permission" {
perm, ok := dst.Value.(int64)
if !ok {
return errors.Errorf("Value for predicate <dgraph.rule.permission> should be of type int")
}
if perm < 0 || perm > 7 {
return errors.Errorf("Can't set <dgraph.rule.permission> to %d, Value for this"+
" predicate should be between 0 and 7", perm)
}
}
// TODO: Figure out why this is Enum. It really seems like an odd choice -- rather than
// specifying it as the same type as presented in su.
edge.ValueType = schemaType.Enum()
var ok bool
edge.Value, ok = b.Value.([]byte)
if !ok {
return errors.Errorf("failure to convert edge type: '%+v' to schema type: '%+v'",
storageType, schemaType)
}
return nil
}
// AssignNsIdsOverNetwork sends a request to assign Namespace IDs to the current zero leader.
func AssignNsIdsOverNetwork(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {
h := hooks.GetHooks()
num.Type = pb.Num_NS_ID
return h.AssignNsIDs(ctx, num)
}
// AssignUidsOverNetwork sends a request to assign UIDs from the current zero leader.
func AssignUidsOverNetwork(ctx context.Context, num *pb.Num) (*pb.AssignedIds, error) {
h := hooks.GetHooks()
num.Type = pb.Num_UID
return h.AssignUIDs(ctx, num)View on GitHub (pinned to 759e242be6)
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
Example fix
// before (mutation sends plain string for a datetime predicate)
{"set":[{"uid":"0x1","created":"1693556000"}]}
// after (send value in the schema-declared format)
{"set":[{"uid":"0x1","created":"2023-09-01T07:33:20Z"}]} Defensive patterns
Strategy: validation
Validate before calling
// Check the value's type against the schema type before mutating
schema, _ := client.Query(context.Background(), `schema(pred: [created]) {}`)
// ensure literal format matches the declared schema type, e.g. datetime:
// value must parse as RFC3339 before being sent
func isValidRFC3339(s string) bool {
_, err := time.Parse(time.RFC3339, s)
return err == nil
} Try / catch
// Go client
resp, err := txn.Mutate(ctx, mu)
if err != nil {
if strings.Contains(err.Error(), "failure to convert edge type") {
// value does not conform to schema type: fix the literal and retry
return fmt.Errorf("mutation value incompatible with schema type: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Attr: [%v] should have @lang directive in schema to mutate e
- illegal rune found "%c", expecting {
- JSON map is followed by illegal rune "%c"
- Malformed JSON
- unexpected type for val for attr: %s while converting to nqu
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/aac0730bccc55a6a.
Report an issue: GitHub.