Skip to content

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

Open
ent/contrib
#582
@lesomnus

Description

@lesomnus
  • 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

Metadata

Metadata

Assignees

No one assigned

    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