{"record":{"id":"31fc3dee0f6c4c5f","repo":"apache/beam","slug":"unable-to-do-row-encoding","errorCode":null,"errorMessage":"unable to do row encoding","messagePattern":"unable to do row encoding","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/xlang/jdbcio/jdbc.go","lineNumber":113,"sourceCode":"\n// jdbcConfig stores the expansion service and configuration for JDBC IO.\ntype jdbcConfig struct {\n\tclasspaths    []string\n\texpansionAddr string\n\tconfig        *config\n}\n\n// TODO(riteshghorse): update the IO to use wrapper created in BigQueryIO.\nfunc toRow(pl any) []byte {\n\trt := reflect.TypeOf(pl)\n\n\tenc, err := coder.RowEncoderForStruct(rt)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"unable to get row encoder\"))\n\t}\n\tvar buf bytes.Buffer\n\tif err := enc(pl, &buf); err != nil {\n\t\tpanic(fmt.Errorf(\"unable to do row encoding\"))\n\t}\n\treturn buf.Bytes()\n}\n\n// Write is a cross-language PTransform which writes Rows to the specified database via JDBC.\n// tableName is a required parameter, and by default, the write statement is generated from it.\n// The generated write statement can be overridden by passing in a WriteStatement option.\n// If an expansion service address is not provided,\n// an appropriate expansion service will be automatically started; however\n// this is slower than having a persistent expansion service running.\n//\n// If no additional classpaths are provided using jdbcio.WriteClasspaths() then the default classpath\n// for that driver would be used. As of now, the default classpaths are present only for PostgreSQL and MySQL.\n//\n// The default write statement is: \"INSERT INTO tableName(column1, ...) INTO VALUES(value1, ...)\"\n// Example:\n//\n//\t  tableName := \"roles\"","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/xlang/jdbcio/jdbc.go#L95-L131","documentation":"In jdbcio.toRow, after successfully obtaining a row encoder, the actual encoding step (enc(pl, &buf)) can still fail; in that case the function panics with 'unable to do row encoding'. This means the value's runtime shape failed to encode into a Beam row buffer even though a matching encoder was found.","triggerScenarios":"Calling jdbcio.Read/Write where a struct element matches the registered encoder but the concrete value passed to enc does not conform — e.g. a nil pointer, a value whose dynamic type differs from the type the encoder was built for, or an internal encoding failure on a field value.","commonSituations":"Passing a nil *Struct to the transform; mixing value and pointer elements of the same struct type in one PCollection so the encoder's expected type doesn't match the runtime value; schema mismatch after changing struct fields without rebuilding.","solutions":["Filter out nil elements before the JDBC write/read transform so enc never receives a nil value.","Keep element types consistent: encode either all values or all pointers of the struct, matching the type used when the encoder was created.","Rebuild/redeploy the pipeline after any struct field changes so encoders match the new schema.","If the panic persists, inspect the dropped error by patching toRow locally (log err from enc) to identify the offending field."],"exampleFix":"// before\np | beam.Create(ctx, []*User{nil, {ID: 1}}) | jdbcio.Write(...) // panic: unable to do row encoding\n\n// after\nfiltered := beam.Filter(p, func(u *User) bool { return u != nil },\n    beam.Create(p, []*User{nil, {ID: 1}}))\nfiltered | jdbcio.Write(s, jdbcio.IO{...})","handlingStrategy":"type-guard","validationCode":"func validUser(u *User) bool { return u != nil }\nfiltered := beam.Filter(s, validUser, input)","typeGuard":"func nonNil[T any](v *T) bool { return v != nil }","tryCatchPattern":null,"preventionTips":["Filter nil elements before JDBC transforms.","Keep element typing consistent (all values or all pointers) across the PCollection.","Rebuild after struct schema changes so encoders stay in sync."],"tags":["beam-go","jdbc","encoding","panic","type-mismatch"],"backgroundTag":"json-marshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}