Note I've made a change in this that assumes you have gorm.io/gen checked out to fix the current issue with Gorm playground not running ootb. See here for details.
Description
We are using Gurego null as an optional type. I've noticed an issue when using DB.Model() to read values that isn't correctly reading null values into a struct. I think the issue was caused by this change to embedded struct handling.
What appears to be the issue is that under the new logic:
WHEN a null column is fetched from the database
AND the field type is a struct (and not a pointer)
IF the returned value is a nil pointer
DO nothing. See the early return without setting a value here
I think what needs to happen is that if the struct field is a non-pointer type (and the column is null), the struct field should be set to the zero value, not skipped (as is happening now). I assume this'll have implications for embedded field handling (i.e. if it's not happening already, a struct embedded via a pointer, we'll need to initialise it if any of the corresponding columns in the row are non-null) but I'm running out of time to spend on this. That should be enough to go on but let me know if more would be useful.
Playground link
https://github.com/go-gorm/playground/pull/762/files
Note I've made a change in this that assumes you have
gorm.io/gen
checked out to fix the current issue with Gorm playground not running ootb. See here for details.Description
We are using Gurego null as an optional type. I've noticed an issue when using
DB.Model()
to read values that isn't correctly reading null values into a struct. I think the issue was caused by this change to embedded struct handling.What appears to be the issue is that under the new logic:
I think what needs to happen is that if the struct field is a non-pointer type (and the column is null), the struct field should be set to the zero value, not skipped (as is happening now). I assume this'll have implications for embedded field handling (i.e. if it's not happening already, a struct embedded via a pointer, we'll need to initialise it if any of the corresponding columns in the row are non-null) but I'm running out of time to spend on this. That should be enough to go on but let me know if more would be useful.