Skip to content
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

Regression of Scan when loading pointer object in a struct #5575

Closed
tab1293 opened this issue Aug 4, 2022 · 7 comments
Closed

Regression of Scan when loading pointer object in a struct #5575

tab1293 opened this issue Aug 4, 2022 · 7 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@tab1293
Copy link

tab1293 commented Aug 4, 2022

GORM Playground Link

go-gorm/playground#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: d01de72. 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?

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Aug 4, 2022
tab1293 referenced this issue Aug 4, 2022
…ues to `Scan()` (#5388)

* fix: reduce allocations when slice of values

* chore[test]: Add benchmark for scan

* chore[test]: add bench for scan slice

* chore[test]: add bench for slice pointer and improve tests

* chore[test]: make sure database is empty when doing slice tests

* fix[test]: correct sql delete statement

* enhancement: skip new if rows affected = 0
@a631807682
Copy link
Member

related to #5431

@ianeal
Copy link

ianeal commented Aug 5, 2022

I've also observed this issue which is blocking us from upgrading.

@ianeal
Copy link

ianeal commented Sep 20, 2022

@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.

@tab1293
Copy link
Author

tab1293 commented Sep 27, 2022

@jinzhu any thoughts around the behavior change introduced with this update?

@miraclesu
Copy link

miraclesu commented Oct 28, 2022

@jinzhu I agree with @a631807682 #5431 (comment), 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"
  })
 }
}

@tsipo
Copy link

tsipo commented Nov 4, 2022

@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!

@yyoshiki41
Copy link

Duplicated issues: #5838

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

7 participants