Skip to content

Commit da564d2

Browse files
committed
Merge branch 'aka-rider-fix-record-panic'
2 parents fcf7db2 + 21dad60 commit da564d2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pgtype/record.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func (dst *Record) DecodeBinary(ci *ConnInfo, src []byte) error {
9898

9999
var binaryDecoder BinaryDecoder
100100
if dt, ok := ci.DataTypeForOID(fieldOID); ok {
101-
if binaryDecoder, ok = dt.Value.(BinaryDecoder); !ok {
102-
return errors.Errorf("unknown oid while decoding record: %v", fieldOID)
103-
}
101+
binaryDecoder, _ = dt.Value.(BinaryDecoder)
102+
}
103+
if binaryDecoder == nil {
104+
return errors.Errorf("unknown oid while decoding record: %v", fieldOID)
104105
}
105106

106107
var fieldBytes []byte

pgtype/record_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ func TestRecordTranscode(t *testing.T) {
102102
}
103103
}
104104

105+
func TestRecordWithUnknownOID(t *testing.T) {
106+
conn := testutil.MustConnectPgx(t)
107+
defer testutil.MustClose(t, conn)
108+
109+
_, err := conn.Exec(`drop type if exists floatrange;
110+
111+
create type floatrange as range (
112+
subtype = float8,
113+
subtype_diff = float8mi
114+
);`)
115+
if err != nil {
116+
t.Fatal(err)
117+
}
118+
defer conn.Exec("drop type floatrange")
119+
120+
var result pgtype.Record
121+
err = conn.QueryRow("select row('foo'::text, floatrange(1, 10), 'bar'::text)").Scan(&result)
122+
if err == nil {
123+
t.Errorf("expected error but none")
124+
}
125+
}
126+
105127
func TestRecordAssignTo(t *testing.T) {
106128
var valueSlice []pgtype.Value
107129
var interfaceSlice []interface{}

0 commit comments

Comments
 (0)