Skip to content

Commit

Permalink
Fix tinkerbell#318 : Starts the db transaction after validating the d…
Browse files Browse the repository at this point in the history
…ata (tinkerbell#369)

## Description
Moves the code for data validation before creating the db transaction.

## Why is this needed
Fixes: tinkerbell#318 

## How Has This Been Tested?
Ran `make test` with Linux host.
  • Loading branch information
mergify[bot] authored Nov 18, 2020
2 parents 23c4fb0 + 8c5dd2b commit 47f1e12
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions db/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (

// CreateTemplate creates a new workflow template
func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error {
tx, err := d.instance.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable})
_, err := wflow.Parse([]byte(data))
if err != nil {
return errors.Wrap(err, "BEGIN transaction")
return err
}

_, err = wflow.Parse([]byte(data))
tx, err := d.instance.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelSerializable})
if err != nil {
return err
return errors.Wrap(err, "BEGIN transaction")
}

_, err = tx.Exec(`
Expand Down

0 comments on commit 47f1e12

Please sign in to comment.