Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScanRows doesn't reset fields in target struct for incoming null values #6819

Open
turip opened this issue Feb 2, 2024 · 3 comments
Open
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@turip
Copy link

turip commented Feb 2, 2024

GORM Playground Link

go-gorm/playground#686

Description

Starting with gorm v1.25.1 (v1.25.0 was not affected), if I use ScanRows on a struct that is not initialized to its default value for all fields GORM will not overwrite those fields that are NULL on SQL side.

An example codpiece can be found at go-gorm/playground#686, but generally speaking we have encountered it when using a non-builtin type too (https://github.com/shopspring/decimal).

@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Feb 2, 2024
@turip
Copy link
Author

turip commented Feb 13, 2024

I have opened a PR with some fixes: https://github.com/go-gorm/gorm/pull/6837/files

@Waldeedle
Copy link
Contributor

Waldeedle commented Apr 3, 2024

I just ran into this issue as well when upgrading gorm. It breaks the example from the docs where you initialize the var once:

    var datasetRow T
    for rows.Next() {
        err := db.ScanRows(rows, &datasetRow)

now I need to reallocate for each scan

    for rows.Next() {
        var datasetRow T
        err := db.ScanRows(rows, &datasetRow)

@Waldeedle
Copy link
Contributor

Waldeedle commented Apr 3, 2024

Actually this is broken since v1.24.6 (time.Time scanning NULL values still have the same error), I will be downgrading to 1.24.5 in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

3 participants