Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick "Check uid list is empty when filling shortest path vars." (#5141) #5152

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,16 +1576,18 @@ func (sg *SubGraph) recursiveFillVars(doneVars map[string]varValue) error {
// fillShortestPathVars reads value of the uid variable from mp map and fills it into From and To
// parameters.
func (sg *SubGraph) fillShortestPathVars(mp map[string]varValue) error {
// The uidVar.Uids can be nil if the variable didn't return any uids. This would mean
// sg.Params.From or sg.Params.To is 0 and the query would return an empty result.
// The uidVar.Uids can be nil or have an empty uid list if the variable didn't
// return any uids. This would mean sg.Params.From or sg.Params.To is 0 and the
// query would return an empty result.

if sg.Params.ShortestPathArgs.From != nil && len(sg.Params.ShortestPathArgs.From.NeedsVar) > 0 {
fromVar := sg.Params.ShortestPathArgs.From.NeedsVar[0].Name
uidVar, ok := mp[fromVar]
if !ok {
return errors.Errorf("value of from var(%s) should have already been populated",
fromVar)
}
if uidVar.Uids != nil {
if uidVar.Uids != nil && len(uidVar.Uids.Uids) > 0 {
if len(uidVar.Uids.Uids) > 1 {
return errors.Errorf("from variable(%s) should only expand to 1 uid", fromVar)
}
Expand All @@ -1600,7 +1602,7 @@ func (sg *SubGraph) fillShortestPathVars(mp map[string]varValue) error {
return errors.Errorf("value of to var(%s) should have already been populated",
toVar)
}
if uidVar.Uids != nil {
if uidVar.Uids != nil && len(uidVar.Uids.Uids) > 0 {
if len(uidVar.Uids.Uids) > 1 {
return errors.Errorf("to variable(%s) should only expand to 1 uid", toVar)
}
Expand Down