@@ -1187,6 +1187,25 @@ func (t *DoltgresType) CallReceive(ctx *sql.Context, val []byte) (any, error) {
11871187func (t * DoltgresType ) ConvertSerialized (ctx context.Context , other val.TupleTypeHandler , val []byte ) ([]byte , error ) {
11881188 ot , ok := other .(* DoltgresType )
11891189 if ! ok {
1190+ if other == nil {
1191+ // TODO: replace this with something much better than this hack
1192+ // `other` will be nil in cases where the parent and child are mismatched (AdaptiveEncoding vs StringEnc for example)
1193+ // Since we do restrict foreign keys to similar types, if the calling type is a string type, we can fairly
1194+ // safely assume that the other type is also a string type. This is implemented specifically for a customer
1195+ // issue, as should be replaced as soon as a real fix is found.
1196+ switch t .ID .TypeName () {
1197+ case "bpchar" , "text" , "varchar" :
1198+ var str string
1199+ if len (val ) > 0 {
1200+ if val [len (val )- 1 ] == 0 {
1201+ str = string (val [:len (val )- 1 ])
1202+ } else {
1203+ str = string (val )
1204+ }
1205+ }
1206+ return t .SerializeValue (ctx , str )
1207+ }
1208+ }
11901209 return nil , errors .Errorf ("expected DoltgresType, got %T" , other )
11911210 }
11921211
@@ -1195,7 +1214,8 @@ func (t *DoltgresType) ConvertSerialized(ctx context.Context, other val.TupleTyp
11951214 return nil , err
11961215 }
11971216
1198- toValue , _ , err := t .ConvertToType (nil , ot , value )
1217+ sqlCtx , _ := ctx .(* sql.Context )
1218+ toValue , _ , err := t .ConvertToType (sqlCtx , ot , value )
11991219 if err != nil {
12001220 return nil , err
12011221 }
0 commit comments