GORM Playground Link
https://github.com/go-gorm/playground/pull/406
Description
There are unexpected scenario when I try to preload substructs of nested anonymous struct.
I reproduced it in playgoround. Here are log trace
banana@DESKTOP-F5UJ1GP:/mnt/c/Users/smoro/playground$ GORM_DIALECT=postgres go test
2021/11/30 02:41:29 testing postgres...
2021/11/30 02:41:30 /mnt/c/Users/smoro/playground/main_test.go:15
[4.732ms] [rows:1] INSERT INTO "users" ("created_at","updated_at","deleted_at","name","age","birthday","company_id","manager_id","active") VALUES ('2021-11-30 02:41:30.143','2021-11-30 02:41:30.143',NULL,'jinzhu',0,NULL,NULL,NULL,false) RETURNING "id"
2021/11/30 02:41:30 /mnt/c/Users/smoro/playground/main_test.go:16
[7.448ms] [rows:1] INSERT INTO "accounts" ("created_at","updated_at","deleted_at","user_id","number") VALUES ('2021-11-30 02:41:30.149','2021-11-30 02:41:30.149',NULL,1,'123') RETURNING "id"
2021/11/30 02:41:30 /mnt/c/Users/smoro/playground/main_test.go:31
[2.577ms] [rows:1] SELECT users.*, 'yo' as something FROM "users" WHERE "users"."id" = 1 AND "users"."deleted_at" IS NULL ORDER BY "users"."id" LIMIT 1
--- FAIL: TestGORM (0.02s)
panic: reflect: call of reflect.Value.Field on string Value [recovered]
panic: reflect: call of reflect.Value.Field on string Value
goroutine 7 [running]:
testing.tRunner.func1.2(0xa52980, 0xc000275428)
/usr/local/go/src/testing/testing.go:1143 +0x332
testing.tRunner.func1(0xc0001b1200)
/usr/local/go/src/testing/testing.go:1146 +0x4b6
panic(0xa52980, 0xc000275428)
/usr/local/go/src/runtime/panic.go:965 +0x1b9
reflect.Value.Field(0xa3c6a0, 0xc00051e380, 0x198, 0x0, 0xa3c6a0, 0xc00051e380, 0x198)
/usr/local/go/src/reflect/value.go:850 +0x125
gorm.io/gorm/schema.(*Field).setupValuerAndSetter.func2(0xa72d60, 0xc00051e380, 0x199, 0xc000515fb0, 0x5, 0xc0000b6b98)
/mnt/c/Users/smoro/playground/gorm/schema/field.go:418 +0xd1
gorm.io/gorm/schema.GetIdentityFieldValuesMap(0xa72d60, 0xc00051e380, 0x199, 0xc0005163b0, 0x1, 0x1, 0x0, 0x1, 0x9, 0x9)
/mnt/c/Users/smoro/playground/gorm/schema/utils.go:113 +0x8fe
gorm.io/gorm/callbacks.preload(0xc000503b00, 0xc0001f2cf0, 0x0, 0x0, 0x0, 0xc000503f50)
/mnt/c/Users/smoro/playground/gorm/callbacks/preload.go:95 +0x9d0
gorm.io/gorm/callbacks.Preload(0xc000503b00)
/mnt/c/Users/smoro/playground/gorm/callbacks/query.go:224 +0xc50
gorm.io/gorm.(*processor).Execute(0xc000200320, 0xc000503b00, 0xadecaa)
/mnt/c/Users/smoro/playground/gorm/callbacks.go:130 +0x3f5
gorm.io/gorm.(*DB).First(0xc000503b00, 0xa30e20, 0xc00051e380, 0xc000515e70, 0x1, 0x1, 0xc000503b00)
/mnt/c/Users/smoro/playground/gorm/finisher_api.go:125 +0x14b
gorm.io/playground.TestGORM(0xc0001b1200)
/mnt/c/Users/smoro/playground/main_test.go:42 +0x465
testing.tRunner(0xc0001b1200, 0xb01e70)
/usr/local/go/src/testing/testing.go:1193 +0xef
created by testing.(*T).Run
/usr/local/go/src/testing/testing.go:1238 +0x2b3
exit status 2
FAIL gorm.io/playground 0.252s
Comment From: glebarez
I experience similar issue
Comment From: sepnotican
same problem
Comment From: jinzhu
Fixed in PR #5130, thank you for your report.