{"record":{"id":"645f6e43834dadbc","repo":"milvus-io/milvus","slug":"unexpected-values-type-t-of-fieldtype-v","errorCode":null,"errorMessage":"unexpected values type(%T) of fieldType %v","messagePattern":"unexpected values type\\(%T\\) of fieldType (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"client/column/conversion.go","lineNumber":102,"sourceCode":"\t\tvar doubles []float64\n\t\tdoubles, ok = any(values).([]float64)\n\t\tscalarField.Data = &schemapb.ScalarField_DoubleData{\n\t\t\tDoubleData: &schemapb.DoubleArray{\n\t\t\t\tData: doubles,\n\t\t\t},\n\t\t}\n\tcase entity.FieldTypeVarChar, entity.FieldTypeString:\n\t\tvar strings []string\n\t\tstrings, ok = any(values).([]string)\n\t\tscalarField.Data = &schemapb.ScalarField_StringData{\n\t\t\tStringData: &schemapb.StringArray{\n\t\t\t\tData: strings,\n\t\t\t},\n\t\t}\n\t}\n\n\tif !ok {\n\t\tpanic(fmt.Sprintf(\"unexpected values type(%T) of fieldType %v\", values, elementType))\n\t}\n\treturn scalarField\n}\n\nfunc values2FieldData[T any](values []T, fieldType entity.FieldType, dim int) *schemapb.FieldData {\n\tfd := &schemapb.FieldData{}\n\tswitch fieldType {\n\t// scalars\n\tcase entity.FieldTypeBool,\n\t\tentity.FieldTypeFloat,\n\t\tentity.FieldTypeDouble,\n\t\tentity.FieldTypeInt8,\n\t\tentity.FieldTypeInt16,\n\t\tentity.FieldTypeInt32,\n\t\tentity.FieldTypeInt64,\n\t\tentity.FieldTypeVarChar,\n\t\tentity.FieldTypeText,\n\t\tentity.FieldTypeString,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/milvus-io/milvus/blob/b43a76673a9fe5f01f158979731dc8fd542df81f/client/column/conversion.go#L84-L120","documentation":"A Go panic in the Milvus SDK's column conversion helper (values2Scalars). After a type-switch over field types, if the generic []T slice stored in the interface cannot be asserted to the concrete slice type the field requires (e.g. the values are []int32 but the field is declared Int64), ok stays false and the SDK panics rather than returning an error. It indicates the Go type of the inserted column data does not match the schema field type.","triggerScenarios":"Building a column via column.NewXxx or the generic conversion path with a Go slice type that disagrees with entity.FieldType: []int32 with FieldTypeInt64, []float32 with FieldTypeDouble, []int with FieldTypeInt32, or any non-string slice for VarChar/String fields (the String case leaves ok false for anything else).","commonSituations":"Schema migrated (Int64 -> Int32) while insertion code kept the old Go type; JSON decoding numbers as []float64 and inserting directly; generics path where values arrive as []any or []interface{}.","solutions":["Match the Go slice element type exactly to the schema field type per the SDK table: BoolVector->[]bool, Int8/16/32->[]int8/16/32, Int64->[]int64, Float->[]float32, Double->[]float64, VarChar->[]string.","Convert before insert: cast []int to []int64, []float64 to []float32, fmt.Sprintf numbers for VarChar.","Check the panic message's %T verb - it prints the actual slice type you passed, which tells you exactly what to convert from.","If types genuinely vary at runtime, switch to building typed columns explicitly (column.NewColumnInt64 etc.) instead of the generic values path."],"exampleFix":"// before\nfieldData := values2Scalars(int32Values, entity.FieldTypeInt64) // panics: %T = []int32\n\n// after\nint64Values := make([]int64, len(int32Values))\nfor i, v := range int32Values {\n    int64Values[i] = int64(v)\n}\nfieldData := values2Scalars(int64Values, entity.FieldTypeInt64)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func scalarSliceForType(fieldType entity.FieldType, values any) error {\n    switch fieldType {\n    case entity.FieldTypeBool:\n        if _, ok := values.([]bool); !ok { return fmt.Errorf(\"want []bool, got %T\", values) }\n    case entity.FieldTypeInt8:\n        if _, ok := values.([]int8); !ok { return fmt.Errorf(\"want []int8, got %T\", values) }\n    case entity.FieldTypeInt16:\n        if _, ok := values.([]int16); !ok { return fmt.Errorf(\"want []int16, got %T\", values) }\n    case entity.FieldTypeInt32:\n        if _, ok := values.([]int32); !ok { return fmt.Errorf(\"want []int32, got %T\", values) }\n    case entity.FieldTypeInt64:\n        if _, ok := values.([]int64); !ok { return fmt.Errorf(\"want []int64, got %T\", values) }\n    case entity.FieldTypeFloat:\n        if _, ok := values.([]float32); !ok { return fmt.Errorf(\"want []float32, got %T\", values) }\n    case entity.FieldTypeDouble:\n        if _, ok := values.([]float64); !ok { return fmt.Errorf(\"want []float64, got %T\", values) }\n    case entity.FieldTypeVarChar, entity.FieldTypeString:\n        if _, ok := values.([]string); !ok { return fmt.Errorf(\"want []string, got %T\", values) }\n    }\n    return nil\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"column conversion panic (likely Go slice type does not match schema field type): %v\", r)\n    }\n}()","preventionTips":["Keep Go slice element types exactly aligned with the schema: Float is float32, Double is float64, Int64 is int64.","Convert decoded data ([]float64 from JSON -> []float32, []int -> []int64) before insert.","Wrap the insert/conversion call in a recover at the batch boundary so type bugs become errors, not crashes.","Read the panic message - the %T verb names the concrete type you actually passed."],"tags":["go","sdk","panic","type-mismatch","insert"],"backgroundTag":null,"analyzedSha":"b43a76673a9fe5f01f158979731dc8fd542df81f","analyzedAt":"2026-08-15T10:29:28.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}