-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Joins and Preload Regression with gorm version 1.25.7 #6834
Comments
I think I found the problem Used the same test used in unit tests in PR #6771 But when using Find with type var find1 []Value it will panic type (
Preload struct {
ID uint
Value string
NestedID uint
}
Join struct {
ID uint
Value string
NestedID uint
}
Nested struct {
ID uint
Preloads []*Preload
Join Join
ValueID uint
}
Value struct {
ID uint
Name string
Nested Nested
}
)
func TestJoinsPreloads(t *testing.T) {
_ = DB.AutoMigrate(&Preload{}, &Join{}, &Nested{}, &Value{})
value := Value{
Name: "value",
Nested: Nested{
Preloads: []*Preload{
{Value: "p1"}, {Value: "p2"},
},
Join: Join{Value: "j1"},
},
}
if err := DB.Create(&value).Error; err != nil {
t.Errorf("failed to create value, got err: %v", err)
}
var err error
// this will succeed
var find Value
err = DB.Joins("Nested").Joins("Nested.Join").Preload("Nested.Preloads").First(&find).Error
if err != nil {
t.Errorf("Failed, got error: %v", err)
}
// this will panic
var values []Value
err = DB.Joins("Nested").Joins("Nested.Join").Preload("Nested.Preloads").Find(&values).Error
if err != nil {
t.Errorf("Failed, got error: %v", err)
}
} the second query will panic var values []Value
err = DB.Joins("Nested").Joins("Nested.Join").Preload("Nested.Preloads").Find(&values).Error
if err != nil {
t.Errorf("Failed, got error: %v", err)
} The unit tests in that PR was not using Find with slice , but only First with pointer to a struct |
Experiencing the same issue. Debugging revealed that the |
go-gorm/gorm#6834 Gorm will be updated again when this is fixed
I have this exact same issue. Upgrading to 1.25.7 completely breaks my entire application consisting of a dozen+ microservices all using gorm. |
Hello @go-gorm maintainers 👋 do you know when this fix will be released? I cannot test this with https://github.com/go-gorm/postgres/releases/tag/v1.5.7 because |
@DAcodedBEAT looks like it was released in 1.25.8 |
GORM Playground Link
go-gorm/playground#688
Description
suppose we have the following data structures
Panic Occurs when Mixing Joins and Preload with the same field
eg query like
will panic with
with version v1.25.6 all the tests passed
this has been discovered with dependency PR in our project RedHatInsights/edge-api#2406
The text was updated successfully, but these errors were encountered: