Skip to content

UUID pointer is never nil #252

@kaasasolut

Description

@kaasasolut

Here is an example to demonstrate the issue:

package main

import (
	"database/sql"
	"fmt"

	_ "github.com/lib/pq"
	uuid "github.com/satori/go.uuid"
	"gopkg.in/src-d/go-kallax.v1"
)

type test struct {
	kallax.Model
	ID   int64 `pk:"autoincr"`
	UUID *uuid.UUID
}

func main() {
	db, _ := sql.Open("postgres", "postgres://testing:[email protected]:5432/testing?sslmode=disable")

	t := NewtestStore(db).MustFindOne(NewtestQuery().Where(kallax.Eq(Schema.test.UUID, nil)))

	if t.UUID == nil {
		fmt.Println("UUID is nil")
	} else if *t.UUID == uuid.Nil {
		fmt.Println("UUID is a pointer to something equal to uuid.Nil")
	} else {
		fmt.Println("UUID is", t.UUID)
	}
}

If nothing panics, the expected result is UUID is nil.
But the actual result is UUID is a pointer to something equal to uuid.Nil.
It's the same with *kallax.UUID.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions