Skip to content

Commit

Permalink
fix(changes): "left" side of report should be the previous path
Browse files Browse the repository at this point in the history
The upper layers & the UI powered by the `Report` method expect that if the `leftRef` is empty, we should just use the `PreviousPath` of the `rightRef` as the `left` dataset to compare to.

This bug only occurs if the `left` side is empty, and currently all our `ChangeReport` consumers have filled in both versions to compare. There is now a test that ensures the behavior is correct.
  • Loading branch information
ramfox committed Mar 8, 2021
1 parent 385c77c commit 32b46ff
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
12 changes: 8 additions & 4 deletions changes/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,18 @@ func (svc *service) columnStatsDelta(left, right interface{}, lCol, rCol *tabula
// Report computes the change report of two sources
// This takes some assumptions - we work only with tabular data, with header rows and functional structure.json
func (svc *service) Report(ctx context.Context, leftRef, rightRef dsref.Ref, loadSource string) (*ChangeReportResponse, error) {
leftDs, err := svc.loader.LoadDataset(ctx, leftRef, loadSource)
rightDs, err := svc.loader.LoadDataset(ctx, rightRef, loadSource)
if err != nil {
return nil, err
}
if rightRef.Path == "" {
rightRef.Path = leftDs.PreviousPath
if leftRef.Path == "" {
if rightDs.PreviousPath == "" {
return nil, fmt.Errorf("dataset has only one version")
}
leftRef.Path = rightDs.PreviousPath
}
rightDs, err := svc.loader.LoadDataset(ctx, rightRef, loadSource)

leftDs, err := svc.loader.LoadDataset(ctx, leftRef, loadSource)
if err != nil {
return nil, err
}
Expand Down
37 changes: 37 additions & 0 deletions lib/changes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package lib

import (
"context"
"testing"

testcfg "github.com/qri-io/qri/config/test"
"github.com/qri-io/qri/event"
"github.com/qri-io/qri/p2p"
testrepo "github.com/qri-io/qri/repo/test"
)

func TestChanges(t *testing.T) {
ctx, done := context.WithCancel(context.Background())
defer done()

mr, err := testrepo.NewTestRepo()
if err != nil {
t.Fatalf("error allocating test repo: %s", err.Error())
}
node, err := p2p.NewQriNode(mr, testcfg.DefaultP2PForTesting(), event.NilBus, nil)
if err != nil {
t.Fatal(err.Error())
}
inst := NewInstanceFromConfigAndNode(ctx, testcfg.DefaultConfigForTesting(), node)

InitWorldBankDataset(ctx, t, inst)
commitref := Commit2WorldBank(ctx, t, inst)

// test ChangeReport with one param
p := &ChangeReportParams{
RightRefstr: commitref.Alias(),
}
if _, err := inst.Dataset().ChangeReport(ctx, p); err != nil {
t.Fatalf("change report error: %s", err)
}
}

0 comments on commit 32b46ff

Please sign in to comment.