1.4.6 is a breaking change! "W10=" instead of "[]"
yvz5 opened this issue · 4 comments
Don't have time to create a playground link. its just too much work. updating 1.4.5 to 1.4.6 broke our system.
Description
we have a table with a column of type jsonb
in postgres. in go, we represent this column with json.RawMessage
. in version 1.4.5 we can save an empty array into jsonb
column and it would save []
in to the table. now, in the new version (1.4.6), it saves the value "W10="
instead of []
which can not be unmarshalled to a known object in go.
I implemented the driver.Valuer
interface on a custom slice-type.
It produces []
for both nil-slices and empty slices (go best-practices state that they should be handled equivalently, so I serialize both variants to the same database value). Since 1.4.6, nil-slices are no longer converted to []
, but to null
.
This took me a while to figure out. Luckily I had unit-tests that triggered not-null-constraint violations in my database.
(Workaround: add exclude gorm.io/driver/postgres v1.4.6
to the go.mod file)
I had the same issue when I upgraded from v1.4.5 to v1.4.6, however, I figure it out that the issue was caused by customised JSON type in GORM 1.0. Since I changed the customised JSON type to official GORM DataTypes, the problem went away.
Please refer the mention on the release note of GORM 2.0 at https://gorm.io/docs/v2_release_note.html#DataTypes-JSON-as-example.
See also: jackc/pgx#1566