{"record":{"id":"83847c803444e837","repo":"dgraph-io/dgraph","slug":"expected-value-of-type-int64-got-v","errorCode":null,"errorMessage":"Expected value of type int64. Got : %v","messagePattern":"Expected value of type int64\\. Got : (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/conversion.go","lineNumber":657,"sourceCode":"\tvar ok bool\n\t// Lets set the object value according to the storage type.\n\tswitch id {\n\tcase StringID:\n\t\tvar v string\n\t\tif v, ok = value.(string); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type string. Got : %v\", value)\n\t\t}\n\t\treturn &api.Value{Val: &api.Value_StrVal{StrVal: v}}, nil\n\tcase DefaultID:\n\t\tvar v string\n\t\tif v, ok = value.(string); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type string. Got : %v\", value)\n\t\t}\n\t\treturn &api.Value{Val: &api.Value_DefaultVal{DefaultVal: v}}, nil\n\tcase IntID:\n\t\tvar v int64\n\t\tif v, ok = value.(int64); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type int64. Got : %v\", value)\n\t\t}\n\t\treturn &api.Value{Val: &api.Value_IntVal{IntVal: v}}, nil\n\tcase FloatID:\n\t\tvar v float64\n\t\tif v, ok = value.(float64); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type float64. Got : %v\", value)\n\t\t}\n\t\treturn &api.Value{Val: &api.Value_DoubleVal{DoubleVal: v}}, nil\n\tcase BoolID:\n\t\tvar v bool\n\t\tif v, ok = value.(bool); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type bool. Got : %v\", value)\n\t\t}\n\t\treturn &api.Value{Val: &api.Value_BoolVal{BoolVal: v}}, nil\n\tcase BinaryID:\n\t\tvar v []byte\n\t\tif v, ok = value.([]byte); !ok {\n\t\t\treturn def, errors.Errorf(\"Expected value of type []byte. Got : %v\", value)","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/conversion.go#L639-L675","documentation":"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.","triggerScenarios":"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.","commonSituations":"Feeding strconv.Atoi results (int) directly; JSON numbers decoded as float64; counters stored as int in application code.","solutions":["Convert explicitly to int64 first: int64(myInt)","If the source is float64, validate integrality and range before int64(v)","If the source may be non-numeric, use types.ParseValue with IntID to get a proper int64 Val"],"exampleFix":"// before\ntypes.ObjectValue(types.IntID, 42) // int, not int64\n// after\ntypes.ObjectValue(types.IntID, int64(42))","handlingStrategy":"type-guard","validationCode":"func isInt64(v interface{}) bool { _, ok := v.(int64); return ok }\nif isInt64(value) { types.ObjectValue(types.IntID, value) } else { /* int64(v) first */ }","typeGuard":"func asInt64(v interface{}) (int64, bool) {\n    switch n := v.(type) {\n    case int64: return n, true\n    case int: return int64(n), true\n    case float64: return int64(n), n == math.Trunc(n)\n    }\n    return 0, false\n}","tryCatchPattern":null,"preventionTips":["Use int64 for all integer values destined for IntID predicates","Convert native int/JSON numbers explicitly at boundaries","Remember Go has no implicit numeric conversion"],"tags":["types","objectvalue","int64","type-mismatch"],"backgroundTag":"value-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}