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

uuid: cannot convert uuid.UUID to UUID #79

Open
jarifibrahim opened this issue May 29, 2018 · 3 comments
Open

uuid: cannot convert uuid.UUID to UUID #79

jarifibrahim opened this issue May 29, 2018 · 3 comments

Comments

@jarifibrahim
Copy link

I have the following struct

type Identity struct {
	gormsupport.Lifecycle
	// Link to User
	UserID uuid.NullUUID `sql:"type:uuid"`
	User   User
}

and

identity := account.Identity{
		User:         user,
		UserID:       uuid.NullUUID{UUID: uuid.NewV4(), Valid: true},
	}
err := s.identityRepo.Create(context.Background(), &identity)

and this is the Create method being called

// Create creates a new record.
func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) error {
	defer goa.MeasureSince([]string{"goa", "db", "identity", "create"}, time.Now())
	if model.ID == uuid.Nil {
		model.ID = uuid.NewV4()
	}
	err := m.db.Create(model).Error
	if err != nil {
		log.Error(ctx, map[string]interface{}{
			"identity_id": model.ID,
			"err":         err,
		}, "unable to create the identity")
		return errs.WithStack(err)
	}

The line m.db.Create(model).Error is failing with cannot convert uuid.UUID to UUID

@tamasd
Copy link

tamasd commented May 30, 2020

Any update on this issue?

@mandaputtra
Copy link

mandaputtra commented Sep 24, 2020

How to solve this issue for now? I have seen this erros

type struct Me {
  ID uuid.UUID
}

...


if Me.ID != nil {
  // cannot convert untyped nil to uuid.UUID
} 

Happen even with uuid.NullUUID

@mandaputtra
Copy link

I solve it using pointer so it could be a nil

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