dgraph-io/dgraph · error

Expected value of type int64. Got : %v

Error message

Expected value of type int64. Got : %v

What it means

ObjectValue for IntID requires the Go value to be exactly int64. If the value is int, int32, uint64, float64, or any other numeric type, the type assertion fails and this error is returned. Go does not implicitly convert between integer types, so even a mathematically valid int must be converted.

Source

Thrown at types/conversion.go:657

	var ok bool
	// Lets set the object value according to the storage type.
	switch id {
	case StringID:
		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_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)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Convert explicitly to int64 first: int64(myInt)
  2. If the source is float64, validate integrality and range before int64(v)
  3. If the source may be non-numeric, use types.ParseValue with IntID to get a proper int64 Val

Example fix

// before
types.ObjectValue(types.IntID, 42) // int, not int64
// after
types.ObjectValue(types.IntID, int64(42))
Defensive patterns

Strategy: type-guard

Validate before calling

func isInt64(v interface{}) bool { _, ok := v.(int64); return ok }
if isInt64(value) { types.ObjectValue(types.IntID, value) } else { /* int64(v) first */ }

Type guard

func asInt64(v interface{}) (int64, bool) {
    switch n := v.(type) {
    case int64: return n, true
    case int: return int64(n), true
    case float64: return int64(n), n == math.Trunc(n)
    }
    return 0, false
}

Prevention

When it happens

Trigger: ObjectValue(types.IntID, value) with value of type int, int32, uint64, or float64 — common when values come from JSON decoding or platform code using native int.

Common situations: Feeding strconv.Atoi results (int) directly; JSON numbers decoded as float64; counters stored as int in application code.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/83847c803444e837. Report an issue: GitHub.