-
Notifications
You must be signed in to change notification settings - Fork 2.3k
ConvertValue() panics when given a nil pointer to a type that implements driver.Valuer with a value receiver #739
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
Comments
Why do you think it is bug? type MyType struct {
v string
};
func (m *MyType) Value() (driver.Value, error) {
if m == nil { // *MyType supports nil pointer for default value
return "UNDEFINED", nil
}
return m.v, nil
} If custom type doesn't support nil, it's callers responsibility to avoid passing nil. |
The argument that was accepted for fixing this issue in Also I would add:
I'm not convinced I fully understand the flow from NamedValueChecker to ColumnConverter to DefaultValueConverter and how this varies between prepared and non prepared statements. But it seems likely that #690 and subsequent patches #708, #709 and #710 moved handling for my case from
True, the type does not natively support If the correct solution is to more fully align the default converter with the |
This change simplifies ConvertValue to only handle the case of uint64 with the high bit set. Other conversions return ErrSkip causing the database/sql default converter to run. As a consequence go-sql-driver#739 is fixed
This simply copies recent changes to ConvertValue from database/sql/driver to ensure that our behaviour only differs for uint64. Fixes go-sql-driver#739
I've fixed this two different ways 99f906a is a more conservative change. It merely updates (copy and paste) e167565 is a more ambitious change. It modifies @methane or @julienschmidt - I'd appreciate some feedback on whether you'd accept a PR following either of these approaches. If so I will prepare one. Thanks. |
I don't think so because
But you can pass untyped nil for it? |
I feel typed nil is:
For former case, we should call method. What is rational for using typed nil instead of untyped nil when the type doesn't support nil receiver? |
We are using a 3rd party package that defines the type and the Our For any pointer that is
If the above argument doesn't work for you then I think the next easiest argument that the current behaviour bad is that it is not deliberate:
|
Why don't you ask the library to support nil receiver?
I'm not interested in difference is deliberate or not.
I'm sorry for missing it. I'm not good at English and your article is too long to read carefully. |
OK, I like this idea. |
Thanks for your effort. I appreciate it. I've been using I have raised #746 for review. |
This simply copies recent changes to ConvertValue from database/sql/driver to ensure that our behaviour only differs for uint64. Fixes go-sql-driver#739
This simply copies recent changes to ConvertValue from database/sql/driver to ensure that our behaviour only differs for uint64. Fixes go-sql-driver#739
Issue description
Given a type that implements
driver.Valuer
using a value receiver. (e.g. this one). Then passing a nil pointer to that type as an argument todb.Exec
will causemysql.converter.ConvertValue()
to panic.This is a regression. Previously this situation would result in a
NULL
argument.Analysis
There is a lengthy discussion of the same issue (resolved some time ago) in
database/sql
here with their fix here.I think the problem is the test here added in #710. The interface is not
nil
and the type assertion succeeds, resulting in a call toValue()
with a nil receiver which is not okay becauseValue()
was implemented on the type with a value receiver not a pointer receiver.Example code
Add the following failing case to
driver_test.go
TestValuerWithValidation()
here.Error log
Configuration
Driver version (or git SHA): 2cc627a
Go version: go1.9.2 darwin/amd64
Server version: MySQL 5.7.19
Server OS: OSX 10.11.6 and also Ubuntu Trusty (Travis-CI)
The text was updated successfully, but these errors were encountered: