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

Join Preload panics #7013

Open
emilienkofman opened this issue May 10, 2024 · 2 comments
Open

Join Preload panics #7013

emilienkofman opened this issue May 10, 2024 · 2 comments
Assignees

Comments

@emilienkofman
Copy link

emilienkofman commented May 10, 2024

GORM Playground Link

go-gorm/playground#735

Description

When using Join and Preload together, if we get more than 20 entries in the database it will panic (I guess due to this beeing 20)

gorm version 1.25.10

obtained stack trace:

Error Trace:	/home/emilien/Workspace/src/github.com/emilienkofman/playground/main_test.go:34
        	Error:      	func (assert.PanicTestFunc)(0xc9e8a0) should not panic
        	            		Panic value:	reflect: slice length out of range in SetLen
        	            		Panic stack:	goroutine 24 [running]:
        	            	runtime/debug.Stack()
        	            		/home/emilien/Workspace/go/src/runtime/debug/stack.go:24 +0x6b
        	            	github.com/stretchr/testify/assert.didPanic.func1()
        	            		/home/emilien/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1050 +0x73
        	            	panic({0xdf8380?, 0xf6ffd0?})
        	            		/home/emilien/Workspace/go/src/runtime/panic.go:770 +0x136
        	            	reflect.Value.SetLen({0xc0003fb100, 0xc00044f068, 0x197}, 0x15)
        	            		/home/emilien/Workspace/go/src/reflect/value.go:2423 +0x85
        	            	gorm.io/gorm/callbacks.preloadEntryPoint(0xc000488c00, {0xc0003dfeb0, 0x1, 0x1}, 0xc000444a28, 0xc000488660, {0x0, 0x0, 0x0})
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/gorm/callbacks/preload.go:128 +0x745
        	            	gorm.io/gorm/callbacks.Preload(0xc000488600)
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/gorm/callbacks/query.go:283 +0x4f7
        	            	gorm.io/gorm.(*processor).Execute(0xc0003feaf0, 0xc000488600)
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/gorm/callbacks.go:130 +0x67c
        	            	gorm.io/gorm.(*DB).Find(0xc000488600, {0xde9280, 0xc00044e258}, {0x0, 0x0, 0x0})
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/gorm/finisher_api.go:170 +0x285
        	            	gorm.io/playground.TestGORM.func1()
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/main_test.go:38 +0xac
        	            	github.com/stretchr/testify/assert.didPanic(0xc0003de590)
        	            		/home/emilien/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1055 +0x119
        	            	github.com/stretchr/testify/assert.NotPanics({0xf71740, 0xc0000f51e0}, 0xc0003de590, {0x0, 0x0, 0x0})
        	            		/home/emilien/go/pkg/mod/github.com/stretchr/testify@v1.8.1/assert/assertions.go:1126 +0x12c
        	            	gorm.io/playground.TestGORM(0xc0000f51e0)
        	            		/home/emilien/Workspace/src/github.com/emilienkofman/playground/main_test.go:34 +0x459
        	            	testing.tRunner(0xc0000f51e0, 0xf26bb0)
        	            		/home/emilien/Workspace/go/src/testing/testing.go:1689 +0x1da
        	            	created by testing.(*T).Run in goroutine 1
        	            		/home/emilien/Workspace/go/src/testing/testing.go:1742 +0x7d3

the test case is inspired with #6715 and likely related to the fix of that previous issue (but I've not been investigating enough)

#6715

@github-actions github-actions bot added type:missing reproduction steps missing reproduction steps type:with reproduction steps with reproduction steps and removed type:missing reproduction steps missing reproduction steps labels May 10, 2024
@emilienkofman
Copy link
Author

looks like this was introduced in 85299bf

@a631807682 do you have any insight on how to fix that? Let me know if I can help. I'm not sure exactly what to do at the moment.

@a631807682
Copy link
Member

looks like this was introduced in 85299bf

@a631807682 do you have any insight on how to fix that? Let me know if I can help. I'm not sure exactly what to do at the moment.

Cap and Len are not handled correctly here, we need to handle them correctly, or avoid them through Append. Are you interested to create a PR for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants