First retains stale *time.Time when reloading a selected SQL NULL into an existing struct
Author: cjbottaroCreated Sep 12, 2026Updated Sep 12, 2026
Labelstype:with reproduction steps
GORM Playground Link
https://github.com/go-gorm/playground/pull/861
Description
Reloading a record leaves an old *time.Time value hanging around after the column becomes NULL.
- Load a row with a non-null timestamp using
First(&record, 1). - Set that column to
NULLin the database. - Call
First(&record, 1)again.
I'd expect the pointer to become nil. Instead, it still holds the old timestamp. Loading the same row into a fresh struct gives nil, as expected. No query errors.
The repro is just an ID and a *time.Time field. No hooks or custom types. Everything runs in one transaction.
Reproduced with GORM v1.31.1 and v1.31.2, PostgreSQL driver v1.6.0. The linked test fails on PostgreSQL; I haven't checked other databases.
Source: go-gorm/gorm