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

Fix null setting on reused objects #6837

Closed
wants to merge 1 commit into from

Conversation

turip
Copy link

@turip turip commented Feb 13, 2024

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Starting from v1.25.1 GORM seems to not reset null fields, causing incosistent behavior compared to the previous way GORM was working.

The fixes I have added are fixing this for Scanner interfaces and time.Time, however there's still a test failure in case of the int and most likely other primitive variables.

I am opening this PR just to illustrate the fixes, but I think we need to debate it further what's the expected behavior.

User Case Description

Starting from v1.25.1 gorm seems to not reset null fields, causing
incosistent behavior with previous behavior.
@turip
Copy link
Author

turip commented Feb 13, 2024

The regression seems to be coming from this PR: #6311

The unit tests are still failing on the integer default value setting. I can dig that out too @jinzhu, but this partially reverts #6311. What do you think about this fix?

@turip turip marked this pull request as draft February 13, 2024 18:30
if test.ID%2 == 0 {
AssertEqual(t, test.ScannerValue, NewDummyString(""))
AssertEqual(t, test.NullScannerValue, nil)
AssertEqual(t, test.IntValue, int(0))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still problematic:

-- FAIL: TestScanNilHandling (9.77s)
    utils.go:40: /Users/turip/src/gorm/tests/scan_test.go:295: expect: 0, got 1
    utils.go:40: /Users/turip/src/gorm/tests/scan_test.go:295: expect: 0, got 3
    utils.go:40: /Users/turip/src/gorm/tests/scan_test.go:295: expect: 0, got 5
    utils.go:40: /Users/turip/src/gorm/tests/scan_test.go:295: expect: 0, got 7

@jinzhu
Copy link
Member

jinzhu commented Apr 26, 2024

This PR is being closed due to failed tests.

@jinzhu jinzhu closed this Apr 26, 2024
@henryjcee
Copy link

Just came here to say that I've also concluded that this is problem for us and it's not 100% clear to me what the previous PR was trying to solve. Will try and get another PR up to fix this but will also make sure I understand completely what's going on first.

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

Successfully merging this pull request may close these issues.

3 participants