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

NullUUID Scan method returns valid true on empty string #109

Open
davidspiess opened this issue Oct 14, 2022 · 2 comments
Open

NullUUID Scan method returns valid true on empty string #109

davidspiess opened this issue Oct 14, 2022 · 2 comments

Comments

@davidspiess
Copy link

var id uuid.NullUUID
id.Scan("")

id.Valid == true // Shouldn't this be false?
@fgm
Copy link

fgm commented Nov 24, 2022

The issue is actually deeper: the code does not do what its comments describe, on both NULL values, empty strings and empty byte slices. The comments say "if an empty UUID comes from a table, we return a null UUID", but actually what happens is:

  • Scan returns a nil error (not a null UUID)
  • Scan leaves the receiver unchanged instead of setting it to uuid.Nil as return a null UUID should probably be interpreted

See https://github.com/google/uuid/blob/v1.3.0/sql.go#L17. for details.

Sample program showing the issue (bug ?) https://go.dev/play/p/EzXldTzj4X_u. Run it locally: playground does not support CGO.

Release 1.3.0 introduced the uuid.Valid field partly for such cases, but that field is not actually used. Maybe the changes to sql.go which used that new feature were not committed when building the release ?

@LogitechUser71592
Copy link

Thank you for this repository code. Me and my team leader are using this to make our recipe blog project for college a whole lot smoother.

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

3 participants