gorm
gorm copied to clipboard
Regression of Scan when loading pointer object in a struct
GORM Playground Link
https://github.com/go-gorm/playground/pull/504
Description
There seems to have been a regression from v1.23.5
to v1.23.6
where loading objects with a pointer struct embed will result in that pointer struct being duplicated across all objects loaded. The commit that caused the regression seems to be this: https://github.com/go-gorm/gorm/commit/d01de7232b46987e239ef19a89d9ab192f453894. There are already two comments on this commit mentioning this behavior.
Can we expect a fix to change this behavior back to not duplicating embed structs across object loads?
related to https://github.com/go-gorm/gorm/issues/5431
I've also observed this issue which is blocking us from upgrading.
@jinzhu Any update on this one? I tried with gorm v1.23.9 and the problem still exists. I can put together a sample program if that would help.
@jinzhu any thoughts around the behavior change introduced with this update?
@jinzhu I agree with @a631807682 https://github.com/go-gorm/gorm/issues/5431#issuecomment-1157263863, revert #5388 solves this problem.
reproduction code
type User struct {
*Embedded
}
type Embedded struct {
ID int
Name string
}
func main() {
db.AutoMigrate(&User{})
db.Create([]User{
{&Embedded{
ID: 1,
Name: "name1",
}},
{&Embedded{
ID: 2,
Name: "name2",
}},
})
users := make([]User, 0, 2)
db.Find(&users)
// github.com/davecgh/go-spew/spew
spew.Dump(users)
}
output
([]main.User) (len=2 cap=2) {
(main.User) {
Embedded: (*main.Embedded)(0xc0014a15f0)({
ID: (int) 2,
Name: (string) (len=5) "name2"
})
},
(main.User) {
Embedded: (*main.Embedded)(0xc0014a15f0)({
ID: (int) 2,
Name: (string) (len=5) "name2"
})
}
}
@jinzhu any updates on a fix for this one (or a plan when to fix it)? We are still holding back to v1.23.5
(and the corresponding drivers), and this issue is blocking us from moving forward with new releases. Thanks!
Duplicated issues: https://github.com/go-gorm/gorm/issues/5838