Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug relating to reuse of types #2077

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion derived_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ func (c *Conn) LoadTypes(ctx context.Context, typeNames []string) ([]*pgtype.Typ
if type_ != nil {
m.RegisterType(type_)
if ti.NspName != "" {
m.RegisterType(&pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec})
nspType := &pgtype.Type{Name: ti.NspName + "." + type_.Name, OID: type_.OID, Codec: type_.Codec}
m.RegisterType(nspType)
result = append(result, nspType)
}
result = append(result, type_)
}
Expand Down
11 changes: 7 additions & 4 deletions derived_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ create type dtype_test as (

types, err := conn.LoadTypes(ctx, []string{"dtype_test"})
require.NoError(t, err)
require.Len(t, types, 3)
require.Equal(t, types[0].Name, "anotheruint64")
require.Equal(t, types[1].Name, "_anotheruint64")
require.Equal(t, types[2].Name, "dtype_test")
require.Len(t, types, 6)
require.Equal(t, types[0].Name, "public.anotheruint64")
require.Equal(t, types[1].Name, "anotheruint64")
require.Equal(t, types[2].Name, "public._anotheruint64")
require.Equal(t, types[3].Name, "_anotheruint64")
require.Equal(t, types[4].Name, "public.dtype_test")
require.Equal(t, types[5].Name, "dtype_test")
})
}
11 changes: 7 additions & 4 deletions pgtype/derived_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ create type dt_test as (
defer conn.Exec(ctx, "drop type dt_test")

dtypes, err := conn.LoadTypes(ctx, []string{"dt_test"})
require.Len(t, dtypes, 3)
require.Equal(t, dtypes[0].Name, "dt_uint64")
require.Equal(t, dtypes[1].Name, "_dt_uint64")
require.Equal(t, dtypes[2].Name, "dt_test")
require.Len(t, dtypes, 6)
require.Equal(t, dtypes[0].Name, "public.dt_uint64")
require.Equal(t, dtypes[1].Name, "dt_uint64")
require.Equal(t, dtypes[2].Name, "public._dt_uint64")
require.Equal(t, dtypes[3].Name, "_dt_uint64")
require.Equal(t, dtypes[4].Name, "public.dt_test")
require.Equal(t, dtypes[5].Name, "dt_test")
require.NoError(t, err)
conn.TypeMap().RegisterTypes(dtypes)

Expand Down
Loading