Skip to content

Commit

Permalink
Fix for panic in fillGroupedVars (#3781)
Browse files Browse the repository at this point in the history
Use DestUIDs() function while accessing uids from child in GroupBy query. This fixes #3768.
  • Loading branch information
pawanrawal committed Aug 9, 2019
1 parent 02375af commit 771307a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions query/groupby.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (sg *SubGraph) formResult(ul *pb.List) (*groupResults, error) {
if attr == "" {
attr = child.Attr
}
if child.DestUIDs != nil && len(child.DestUIDs.Uids) != 0 {
if len(child.DestUIDs.GetUids()) > 0 {
// It's a UID node.
for i := 0; i < len(child.uidMatrix); i++ {
srcUid := child.SrcUIDs.Uids[i]
Expand Down Expand Up @@ -295,7 +295,7 @@ func (sg *SubGraph) fillGroupedVars(doneVars map[string]varValue, path []*SubGra
if attr == "" {
attr = child.Attr
}
if len(child.DestUIDs.Uids) != 0 {
if len(child.DestUIDs.GetUids()) > 0 {
// It's a UID node.
for i := 0; i < len(child.uidMatrix); i++ {
srcUid := child.SrcUIDs.Uids[i]
Expand Down
24 changes: 24 additions & 0 deletions query/query0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,30 @@ func TestGroupByFriendsMultipleParentsVar(t *testing.T) {
require.JSONEq(t, `{"data":{"me":[{"uid":"0x18","name":"Glenn Rhee","val(f)":2},{"uid":"0x1","name":"Michonne","val(f)":1},{"uid":"0x17","name":"Rick Grimes","val(f)":1},{"uid":"0x19","name":"Daryl Dixon","val(f)":1},{"uid":"0x1f","name":"Andrea","val(f)":1},{"uid":"0x65","val(f)":1}]}}`, js)
}

func TestGroupBy_FixPanicForNilDestUIDs(t *testing.T) {
// This a fix for GitHub issue #3768.
query := `
{
var(func: eq(name, "abcdef")) @ignorereflex {
random_nonexistent {
f as uid
}
}
me(func: uid(f)) @groupby(uid) {
a as count(uid)
}
me2(func: uid(f)) {
val(a)
}
}
`
js := processQueryNoErr(t, query)
require.JSONEq(t, `{"data": {"me2": []}}`, js)

}

func TestMultiEmptyBlocks(t *testing.T) {

query := `
Expand Down

0 comments on commit 771307a

Please sign in to comment.