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

@@ -64,7 +64,9 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
return nil, err
}
uc.mutation = mutation
node, err = uc.sqlSave(ctx)
if node, err = uc.sqlSave(ctx); err != nil {
return nil, err
}
mutation.id = &node.ID
mutation.done = true
return node, err
@@ -175,11 +177,11 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
}
}
}
mutation.id = &nodes[i].ID
mutation.done = true
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
mutation.done = true
id := specs[i].ID.Value.(int64)
nodes[i].ID = int(id)
return nodes[i], nil