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 data unmarshal to the pointer of point should be nil #1641

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danie1Lin
Copy link

When passing the pointer of the pointer. The pointer of the pointer will still be initialized if a null value is returned. According to the document, it should be nil. And this change include data == nil and data == []byte{} condition.

My test type

type NullTime struct {
	Time  time.Time
	Valid bool
}

func (v *NullTime) UnmarshalCQL(info gocql.TypeInfo, data []byte) error {
	var t *time.Time
	err := gocql.Unmarshal(info, data, &t)
	fmt.Println(info, "data", string(data), "time", t)
	if t == nil {
		v.Valid = false
		return nil
	} else {
		v.Time = *t
	}
	if err == nil {
		v.Time = v.Time.In(time.UTC).Truncate(time.Millisecond)
		v.Valid = true
	}
	return err
}

before the change, output:

timestamp data  time 0001-01-01 00:00:00 +0000 UTC

after change, output:

timestamp data  time <nil>

@martin-sucha
Copy link
Contributor

Hi! Thanks for the pull request. Unfortunately, the proposed change is not a correct fix. It would cause even empty strings that are not null to be unmarshaled as nil into *string. Could you please open an issue and share more information to reproduce? Is the time value unmarshed from a time column or is it embedded in some user defined type or collection? Which version of gocql are you using?

@danie1Lin
Copy link
Author

@martin-sucha Thank you. #1643. Here is the issue.

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.

None yet

2 participants