entc/gen: fix nil dereference (SIGSEGV) on db errors during Save with Hooks (#1629)

* entc/gen: check for errors before assuming success when save has hooks

* entc/integration,examples: update generated code
This commit is contained in:
Matthew Gabeler-Lee
2021-06-09 01:56:11 -04:00
committed by GitHub
parent 7428167a14
commit 110073c982
100 changed files with 465 additions and 269 deletions

View File

@@ -120,11 +120,11 @@ func ({{ $receiver }} *{{ $builder }}) Save(ctx context.Context) ([]*{{ $.Name }
}
}
}
mutation.{{ $.ID.BuilderField }} = &nodes[i].{{ $.ID.StructField }}
mutation.done = true
if err != nil {
return nil, err
}
mutation.{{ $.ID.BuilderField }} = &nodes[i].{{ $.ID.StructField }}
mutation.done = true
{{- if and $.ID.UserDefined (or $.ID.IsString $.ID.IsUUID) }}
{{- /* Do nothing, because these 2 types must be supplied by the user. */ -}}
{{- else }}