-
Notifications
You must be signed in to change notification settings - Fork 219
Closed
Description
Describe the bug
If driver.Valuer is implemented as a value receiver on a struct, and that struct is referenced via a pointer, Goqu panics when converting to SQL.
To Reproduce
type Person struct {
address *Address
}
type Address struct {
// ...
}
func (m Address ) Value() (driver.Value, error) { // <- Address implements driver.Valuer with value receiver
buf, err := json.Marshal(m)
if err != nil {
return nil, fmt.Errorf("error marshaling to JSON: %w", err)
}
return string(buf), nil
}
func main() {
p := &Person{} // <- p.Address is nil
builder := goqu.Insert("person").Rows(p)
query, args, _ := builder.ToSQL() // <- Panics: panic: value method github.com.../models.Address.Value called using nil *Address pointer
}
Expected behavior
The Address property on Person should be converted to NULL.
Dialect:
- [ *] postgres
- [ *] mysql
- [ *] sqlite3
Additional context
This same type of issue affected the Go std lib back in the day and was fixed: golang/go#8415
Metadata
Metadata
Assignees
Labels
No labels