Skip to content

Model(A).FindInBatches(B) cause panic: reflect: Field index out of range #7737

@Vovan-VE

Description

@Vovan-VE

GORM Playground Link

go-gorm/playground#848

Description

type A struct {
	Foo int   // [0]
	Bar int   // [1]
	Baz int   // [2]
}
type B struct {
	A       // [0]
	Lol int // [1]
}

func _() {
	var chunk []B
	db.Model(A{})._.FindInBatches(&chunk, ...)
	//       ^^^                  ^^^^^^
	//        A                     B
}

Filling field Baz with index 2 (discovered from Model(A{})) cause a panic, because field index 2 checked in type B.

panic: reflect: Field index out of range
  • go 1.24.12
  • gorm.io/gorm v1.31.1
  • gorm.io/driver/postgres v1.6.0

rel

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions