GORM Playground Link
Sorry I didn't use the official playground since there is no model that use the json serializer. You can still find a repo to reproduce here: https://github.com/LaGregance/gorm-save-bug
Description
After upgrading GORM to last version (v1.24.3), I cannot save my model anymore if there include a json field that use the json serializer. I get the following error when saving:
failed to encode args[1]: unable to encode &schema.serializer{Field:(*schema.Field)(0xc0002b65a0), Serializer:schema.SerializerInterface(nil), SerializeValuer:schema.JSONSerializer{}, Destination:reflect.Value{typ:(*reflect.rtype)(0x1584920), ptr:(unsafe.Pointer)(0xc000245470), flag:0x199}, Context:(*context.emptyCtx)(0xc00009c000), value:interface {}(nil), fieldValue:(*database.UserMetadata)(0xc00027acf0)} into text format for jsonb (OID 3802): json: unsupported value: encountered a cycle via *schema.Schema
Not that the json field is of type UserMetadata like that :
type UserMetadata struct {
Hello string
World uint
Big *big.Int
}
So I add a big.Int because it's my case in production, but I got the same error if I remove this field and only keep the string & uint ones. I use postgresql 13.7
Thanks.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: bastengao
I have the same issue on 1.24.3, and i got error
failed to encode args[9]: unable to encode &schema.serializer{Field:(*schema.Field)(0x1400089e000), Serializer:schema.SerializerInterface(nil), SerializeValuer:schema.JSONSerializer{}, Destination:reflect.Value{typ:(*reflect.rtype)(0x1066b8020), ptr:(unsafe.Pointer)(0x1400093cdd0), flag:0x199}, Context:(*context.emptyCtx)(0x14000058190), value:interface {}(nil), fieldValue:map[string]interface {}(nil)} into text format for json (OID 114): json: unsupported value: encountered a cycle via *schema.Schema
type Activity struct {
ID int64
// 10th column
Parameters map[string]any `gorm:"serializer:json"`
}
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: wdmcode
I also encountered the same problem. I spent a day checking it, thinking that I used it in an incorrect way. Finally I downgraded it to 1.23.0
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
This is caused by upgrading from pgx@v4.x.x to pgx@v5.x.x. We will fix or give feedback to pgx later. I don't have enough time to solve it at the moment, I will mark the cause of the problem for the time being, and we will fix it or give feedback to pgx later. We would be happy if someone would like to create a PR for this or follow it up in pgx.
https://github.com/jackc/pgx/blob/e66ad1bcecedaa3032a16f0f71b1878502f9cb8b/extended_query_builder.go#L76 https://github.com/jackc/pgx/blob/e66ad1bcecedaa3032a16f0f71b1878502f9cb8b/extended_query_builder.go#L126
refer to https://github.com/jackc/pgx/issues/1430
Comment From: deefdragon
For anyone else encountering this, Downgrading to the following versions in go.mod worked for me. (tho I did have to go through and finagle some indexes to get migration to work properly)
gorm.io/driver/postgres v1.4.5
gorm.io/gorm v1.24.4
Comment From: fabstu
Had a similar issue with time.Time, I downgraded aswell.
Comment From: a631807682
pgx v5.3.0 was released
go get -u gorm.io/driver/postgres