dgraph-io/dgraph · error
Expected value of type float64. Got : %v
Error message
Expected value of type float64. Got : %v
What it means
ObjectValue for FloatID requires the Go value to be exactly float64. Any other numeric type (int, int64, float32) fails the type assertion and produces this error. The offending value is printed in the message.
Source
Thrown at types/conversion.go:663
return def, errors.Errorf("Expected value of type string. Got : %v", value)
}
return &api.Value{Val: &api.Value_StrVal{StrVal: v}}, nil
case DefaultID:
var v string
if v, ok = value.(string); !ok {
return def, errors.Errorf("Expected value of type string. Got : %v", value)
}
return &api.Value{Val: &api.Value_DefaultVal{DefaultVal: v}}, nil
case IntID:
var v int64
if v, ok = value.(int64); !ok {
return def, errors.Errorf("Expected value of type int64. Got : %v", value)
}
return &api.Value{Val: &api.Value_IntVal{IntVal: v}}, nil
case FloatID:
var v float64
if v, ok = value.(float64); !ok {
return def, errors.Errorf("Expected value of type float64. Got : %v", value)
}
return &api.Value{Val: &api.Value_DoubleVal{DoubleVal: v}}, nil
case BoolID:
var v bool
if v, ok = value.(bool); !ok {
return def, errors.Errorf("Expected value of type bool. Got : %v", value)
}
return &api.Value{Val: &api.Value_BoolVal{BoolVal: v}}, nil
case BinaryID:
var v []byte
if v, ok = value.([]byte); !ok {
return def, errors.Errorf("Expected value of type []byte. Got : %v", value)
}
return &api.Value{Val: &api.Value_BytesVal{BytesVal: v}}, nil
// Geo, datetime, and BigFloat are stored in binary format in the N-Quad, so lets
// convert them here.
case BigFloatID:
b, err := toBinary(id, value)View on GitHub (pinned to 759e242be6)
Solutions
- Convert explicitly: float64(v) before the call
- Ensure the value's Go type matches the predicate's schema type (int64 for int schema, float64 for float schema)
- Parse raw literals via types.ParseValue(types.FloatID, ...) so the resulting Val.Value is float64
Example fix
// before types.ObjectValue(types.FloatID, int64(7)) // error // after types.ObjectValue(types.FloatID, float64(7))
Defensive patterns
Strategy: type-guard
Validate before calling
func isFloat64(v interface{}) bool { _, ok := v.(float64); return ok }
if isFloat64(value) { types.ObjectValue(types.FloatID, value) } else { /* float64(v) first */ } Type guard
func asFloat64(v interface{}) (float64, bool) {
switch n := v.(type) {
case float64: return n, true
case float32: return float64(n), true
case int64: return float64(n), true
}
return 0, false
} Prevention
- Use float64 for all float values destined for FloatID predicates
- Convert int64/float32 explicitly before ObjectValue
- Align the Go value type with the predicate schema type at construction time
When it happens
Trigger: ObjectValue(types.FloatID, value) where value is int64, int, float32, or a non-number — e.g. passing an int64 result straight from an IntID Val into a FloatID ObjectValue.
Common situations: Cross-type copying of values between predicates; JSON numbers decoded into float32; hand-built mutation payloads with mismatched schema types.
Related errors
- Expected value of type string. Got : %v
- Expected value of type int64. Got : %v
- UID must be present and non-zero while deleting edges
- facet value can only be string/number/bool
- facets format should be of type map for scalarlist predicate
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/51ed1c796f0fe48b.
Report an issue: GitHub.