{"record":{"id":"f547140bddc83930","repo":"go-gorm/gorm","slug":"invalid-field-type-v-for-unixsecondserializer-o","errorCode":null,"errorMessage":"invalid field type %#v for UnixSecondSerializer, only int, uint supported","messagePattern":"invalid field type %#v for UnixSecondSerializer, only int, uint supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/serializer.go","lineNumber":155,"sourceCode":"\t\t} else {\n\t\t\tresult = time.Unix(int64(uv), 0).UTC() //nolint:gosec\n\t\t}\n\tcase *int, *int8, *int16, *int32, *int64:\n\t\tif rv.IsZero() {\n\t\t\treturn nil, nil\n\t\t}\n\t\tresult = time.Unix(rv.Elem().Int(), 0).UTC()\n\tcase *uint, *uint8, *uint16, *uint32, *uint64:\n\t\tif rv.IsZero() {\n\t\t\treturn nil, nil\n\t\t}\n\t\tif uv := rv.Elem().Uint(); uv > math.MaxInt64 {\n\t\t\terr = fmt.Errorf(\"integer overflow conversion uint64(%d) -> int64\", uv)\n\t\t} else {\n\t\t\tresult = time.Unix(int64(uv), 0).UTC() //nolint:gosec\n\t\t}\n\tdefault:\n\t\terr = fmt.Errorf(\"invalid field type %#v for UnixSecondSerializer, only int, uint supported\", fieldValue)\n\t}\n\treturn\n}\n\n// GobSerializer gob serializer\ntype GobSerializer struct{}\n\n// Scan implements serializer interface\nfunc (GobSerializer) Scan(ctx context.Context, field *Field, dst reflect.Value, dbValue interface{}) (err error) {\n\tfieldValue := reflect.New(field.FieldType)\n\n\tif dbValue != nil {\n\t\tvar bytesValue []byte\n\t\tswitch v := dbValue.(type) {\n\t\tcase []byte:\n\t\t\tbytesValue = v\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"failed to unmarshal gob value: %#v\", dbValue)","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/go-gorm/gorm/blob/1d6ce99528060be18a42be09aca8d39efcb47f28/schema/serializer.go#L137-L173","documentation":"UnixSecondSerializer.Value only accepts signed/unsigned integers and their pointer forms. Any other Go type on a field tagged with serializer:unixsecond — time.Time, string, float, bool, structs — hits the default branch and is rejected with the field's actual type printed via %#v.","triggerScenarios":"Changing a field from int64 to time.Time but keeping `gorm:\"serializer:unixsecond\"`; applying the tag to string-encoded timestamps; floats used for second fractions.","commonSituations":"Model evolution where the tag outlives the type; copy-pasting the serializer tag onto time.Time fields; mixing conventions across a codebase.","solutions":["Remove the serializer tag from time.Time fields — GORM stores them natively.","Keep the tag only on integer (or integer-pointer) fields.","For string inputs, parse to int64 in a setter/BeforeSave hook rather than relying on the serializer."],"exampleFix":"// before\nCreatedAt time.Time `gorm:\"serializer:unixsecond\"` // unsupported type\n\n// after\nCreatedAt time.Time // native handling","handlingStrategy":"type-guard","validationCode":"// Only integer kinds may carry the unixsecond serializer\nfunc unixSecondTagValid(f reflect.StructField) bool {\n    if !strings.Contains(f.Tag.Get(\"gorm\"), \"unixsecond\") { return true }\n    switch f.Type.Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n         reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Ptr:\n        return true\n    }\n    return false\n}","typeGuard":"func isUnixSecondCompatible(v any) bool {\n    switch v.(type) {\n    case int, int8, int16, int32, int64,\n         uint, uint8, uint16, uint32, uint64,\n         *int, *int8, *int16, *int32, *int64,\n         *uint, *uint8, *uint16, *uint32, *uint64:\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err := db.Create(&rec).Error; err != nil {\n    if strings.Contains(err.Error(), \"UnixSecondSerializer\") {\n        return fmt.Errorf(\"field type incompatible with unixsecond serializer; use int fields or drop the tag: %w\", err)\n    }\n    return err\n}","preventionTips":["Drop serializer:unixsecond when changing a field to time.Time.","Code-review tag/type pairs during model refactors.","CI-test all serialized fields round-trip."],"tags":["gorm","serializer","unixsecond","type-mismatch"],"backgroundTag":null,"analyzedSha":"1d6ce99528060be18a42be09aca8d39efcb47f28","analyzedAt":"2026-08-15T13:01:23.433Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}