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
When reading from the db, If there's a gorm:"default:null" then the returned resource doesn't have it's values set correctly. #6351
Comments
This is really strange. Here data is nil so the field is not set. Lines 797 to 800 in 11fdf46
Does this need to be fixed? @a631807682 |
We do not recommend re-using the model in the finished api, it may have worked in some intermediate version of gorm for some reason, but this was actually an accident, due to a bug caused by an optimization commit. |
I feel like this is a breaking change... we used this successfully in the following versions:
|
Need to investigate |
This behavior was last changed in v1.23.0. It is not expected that such behavior occurs after this version. |
I respect your decision as the maintainers, but it would seem trivial to support both embedded and this behavior by simply adding a function call before/while reading the resource like:
|
Added RW.clearDefaultNullResourceFields which will clear fields in the resource which are defaulted to a null value. This addresses the unfixed issue in gorm: go-gorm/gorm#6351
) Added RW.clearDefaultNullResourceFields which will clear fields in the resource which are defaulted to a null value. This addresses the unfixed issue in gorm: go-gorm/gorm#6351
This solves the problem to a certain extent, but doesn't fit well in gorm.
|
GORM Playground Link
go-gorm/playground#602
Description
We recently updated our gorm dependency and we had some regression tests fail. During our investigation we discovered that when the there's a gorm tag of
default:null
the value from the database is not set in the returned resource.We would expect that anytime a resource is read that it's value should match the values in the database, regardless of any gorm tags.
The text was updated successfully, but these errors were encountered: