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

Null value cannot be unpacked into *[16]uint8 #254

Open
gronka opened this issue May 15, 2023 · 0 comments
Open

Null value cannot be unpacked into *[16]uint8 #254

gronka opened this issue May 15, 2023 · 0 comments

Comments

@gronka
Copy link

gronka commented May 15, 2023

When the value ProjectId is value is null in the database, I get these errors:

1:22AM ERR could not get by surfer email 2@2.2
1:22AM ERR can not unmarshal X uuid into *[16]uint8

Here is the code. SurfersStruct was generated using schemagen:

type SurfersStruct struct {
	Email           string
	Name            string
	ProjectId       [16]byte
	SurferId        [16]byte
}

func (surfer *SurfersStruct) GetByEmail(session *gocqlx.Session, email string) {
	stmt, names := qb.Select("brain.surfers").Where(qb.Eq("email")).Limit(1).ToCql()
	res := session.Query(stmt, names).Bind(email)
	if err := res.GetRelease(surfer); err != nil {
		uy.Error("could not get by surfer email " + email)
		uy.Error(err.Error())
	}
}

I'm using github.com/scylladb/gocqlx/v2 v2.8.0.

The two fixes I see are to change ProjectId to a pointer *[16]byte or to make sure project_id is never null in the database.

This seems like the most common use case, so I'm not sure if this is a bug, if I'm doing something wrong, or if this is expected behavior for a reason.

For now I think I'll fork schemagen to replace [16]byte with *gocql.UUID or gocql.UUID.

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

No branches or pull requests

1 participant