Skip to content

Commit

Permalink
fix(actions.SaveDataset): delay inferring values until after writing …
Browse files Browse the repository at this point in the history
…changes

based on the set-value cascade, inference should be the last thing that occurs in the dataset creation step, only adding
vital missing components that are required by the provided state but not present
  • Loading branch information
b5 committed Mar 6, 2019
1 parent befcdf8 commit 86f57fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions actions/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func SaveDataset(node *p2p.QriNode, changes *dataset.Dataset, secrets map[string
node.LocalStreams.Print("✅ transform complete\n")
}

// Infer any values about the incoming change before merging it with the previous version.
if err = base.InferValues(pro, changes); err != nil {
return
}

if prevPath == "" && changes.BodyFile() == nil && changes.Structure == nil {
err = fmt.Errorf("creating a new dataset requires a structure or a body")
return
Expand All @@ -84,6 +79,10 @@ func SaveDataset(node *p2p.QriNode, changes *dataset.Dataset, secrets map[string
mutable.Assign(changes)
changes = mutable

if err = base.InferValues(pro, changes); err != nil {
return
}

// let's make history, if it exists:
changes.PreviousPath = prevPath

Expand Down
12 changes: 6 additions & 6 deletions lib/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ func TestDatasetRequestsDiff(t *testing.T) {
{"two fully qualified references",
dsRef1.String(), dsRef2.String(),
"",
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2910, Inserts: 1, Updates: 9, Deletes: 0, Moves: 0},
10,
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2807, Inserts: 1, Updates: 7, Deletes: 0, Moves: 0},
8,
},
{"fill left path from history",
"", dsRef2.AliasString(),
"",
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2910, Inserts: 1, Updates: 9, Deletes: 0, Moves: 0},
10,
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2807, Inserts: 1, Updates: 7, Deletes: 0, Moves: 0},
8,
},
{"populate from selected references",
"", "",
"",
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2910, Inserts: 1, Updates: 9, Deletes: 0, Moves: 0},
10,
&DiffStat{Left: 42, Right: 44, LeftWeight: 2570, RightWeight: 2807, Inserts: 1, Updates: 7, Deletes: 0, Moves: 0},
8,
},
{"two local file paths",
"testdata/jobs_by_automation/body.csv", "testdata/jobs_by_automation_2/body.csv",
Expand Down

0 comments on commit 86f57fa

Please sign in to comment.