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

entproto: rpc Create does not respect default value. #4069

Open
2 tasks done
lesomnus opened this issue May 21, 2024 · 0 comments · May be fixed by ent/contrib#582
Open
2 tasks done

entproto: rpc Create does not respect default value. #4069

lesomnus opened this issue May 21, 2024 · 0 comments · May be fixed by ent/contrib#582

Comments

@lesomnus
Copy link

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

func (User) Fields() []ent.Field {
	return []ent.Field{
		field.UUID("id", uuid.UUID{}).
			Unique().
			Immutable().
			Default(uuid.New). // This works
			Annotations(entproto.Field(1)),
		field.String("name").
			DefaultFunc(randstr). // This not work.
			Annotations(entproto.Field(2)),

		field.Time("created_at").
			Immutable().
			Default(time.Now). // This not work.
			Annotations(entproto.Field(2)),
	}
}

This happens because generated code (func (x *XService) createBuilder) calls m.SetXXX(v) even if v is the zero value.

Expected Behavior 🤔

Fucntion given by DefaultFunc or Default must be invoked and the result must be set as a field value.

Steps to Reproduce 🕹

Steps:

  1. Genreate gRPC services with Create RPC.
  2. Call Create.

Your Environment 🌎

Tech Version
Go 1.22.3
Ent 0.12.5
Database sliqte3
Driver mem
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 a pull request may close this issue.

1 participant