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

endless loop in Save #6799

Open
omniskop opened this issue Jan 20, 2024 · 0 comments
Open

endless loop in Save #6799

omniskop opened this issue Jan 20, 2024 · 0 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@omniskop
Copy link

omniskop commented Jan 20, 2024

GORM Playground Link

go-gorm/playground#684

Description

Calling Save with a pointer to an interface{} results in an endless loop.

This is due to it trying to dereference the interfacing using reflect.Indirect which only works with pointers.
See finisher_api.go:78

I tried two different approaches to fix this:

Solution 1: Return an error

Change the loop to not dereference interfaces. This will result in an "unsupported data" error down the line.
This can be an acceptable solution and is better than an endless loop.

Solution 2: Support it

Use reflectValue.Elem() instead of reflect.Indirect() which works with interfaces and pointers.
Just doing that will also result in an "unsupported data" error though.
This is due to callbacks.go only supporting pointers and no interfaces.
I changed that place to also accept interfaces but the code later tries to use CanAddr on the interface and that doesn't work. All of this is due to it trying to modify the data passed to Save.

I don't know enough about this code to try to implement solution 2 I have thus created a Pull Request for solution 1 (#6800 ). If that should not be the desired solution feel free to reject it and alternatives can be discussed here.

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

2 participants