-
Notifications
You must be signed in to change notification settings - Fork 551
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
types.NullDecimal with nil causes panic #404
Comments
Hey there. This is a problem in the decimal library that we use. I've created an issue over there (you can see it referenced above) to see if we can't get a fix. |
Since the author cautioned against using "null" types with his Could it be extracted to the null package and have a similar API with a struct field called |
Yeah. It seems like maybe what we should do is add MarshalJSON/UnmarshalJSON to NullDecimal directly. Since it's a value type it will always be able to do the correct thing. |
The linked issue was closed, so one less panic to worry about. I don't want to commit to submitting a PR yet, but will look for time to work on this today or tomorrow and give an update here. |
cc @AlexDunmow This is obviously still an issue. I'm actually wondering if we could go against the grain and use decimal.Big as a value type instead. It makes working with it more annoying since you'd have The pointer was a primary concern when I was choosing a decimal type to use for sqlboiler, I'm sad to see that the choice indeed is coming back to bite me. For people who don't care and just want to work around the problem, you could probably type replace with https://github.com/shopspring/decimal which doesn't use a pointer and be okay. |
Usually, marshalling/unmarshalling already follows an API where you use references ( Sorry I haven't got around to look at it as I said. Life got super busy when I was supposed to be on vacation. |
In my opinion, https://github.com/shopspring/decimal is the superior library, especially when having to do calculations. |
Interesting. It implements JSON marshalling/unmarshalling too. Maybe that isn't a concern, but the last commit was one year ago. Solid libraries usually get at those stages. |
Probably going to move to shopspring decimal in v4 |
This should actually be fixed on dev as soon as I push today's changes. |
Interestingly, I am running v4 and still have this issue. I would support @AlexDunmow with the idea to migrate to a better library. Especially since the original decimal library seems to have some other problems like too-new and broken version for a while. Like for two years now if I am not mistaken... My model: // SourcePhistat is an object representing the database table.
type Source struct {
ID int `boil:"id" json:"id" toml:"id" yaml:"id"`
Score types.NullDecimal `boil:"score" json:"score,omitempty" toml:"score" yaml:"score,omitempty"`
R *sourcePhistatR `boil:"-" json:"-" toml:"-" yaml:"-"`
L sourcePhistatL `boil:"-" json:"-" toml:"-" yaml:"-"`
} Debug output:
Model and output were simplified for exemplary purposes. |
I think the issue is I never did push the bump to the version on the dev branch. My apologies. It should be there now. |
Not a generation problem.
What version of SQLBoiler are you using (
sqlboiler --version
)?v3.0.1
If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)
No
If this happened at runtime what code produced the issue? (if not applicable leave blank)
What is the output
runtime error: invalid memory address or nil pointer dereference
Further information. What did you do, what did you expect?
It is expected that
d := types.NewNullDecimal(nil)
ord := NullDecimal{}
orvar d NullDecimal
follow what its documentation states:The text was updated successfully, but these errors were encountered: