Repository: dgraph-io/dgraph
File: edgraph/server.go (Go)

Code before:
	if op.DropAll || op.DropOp == api.Operation_ALL {
		return true
	}
	return false
}

func verifyUniqueWithinMutation(qc *queryContext) error {
	if len(qc.uniqueVars) == 0 {
		return nil
	}

	for i := range qc.uniqueVars {
		gmuIndex, rdfIndex := decodeIndex(i)
		// handles cases where the mutation was pruned in updateMutations
		if gmuIndex >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex] == nil || rdfIndex >= uint32(len(qc.gmuList[gmuIndex].Set)) {
			continue
		}
		pred1 := qc.gmuList[gmuIndex].Set[rdfIndex]
		pred1Value := dql.TypeValFrom(pred1.ObjectValue).Value
		for j := range qc.uniqueVars {
			if i == j {
				continue
			}
			gmuIndex2, rdfIndex2 := decodeIndex(j)
			// bounds check for the second predicate, which could also have been pruned
			if gmuIndex2 >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex2] == nil || rdfIndex2 >= uint32(len(qc.gmuList[gmuIndex2].Set)) {
				continue
			}
			pred2 := qc.gmuList[gmuIndex2].Set[rdfIndex2]
			if pred2.Predicate == pred1.Predicate && dql.TypeValFrom(pred2.ObjectValue).Value == pred1Value &&
				pred2.Subject != pred1.Subject {
				return errors.Errorf("could not insert duplicate value [%v] for predicate [%v]",
					pred1Value, pred1.Predicate)
			}
		}
	}
	return nil
}

func isUpsertCondTrue(qc *queryContext, gmuIndex int) bool {
	condVar := qc.condVars[gmuIndex]
	if condVar == "" {
		return true
	}

	uids, ok := qc.uidRes[condVar]
	return ok && len(uids) == 1
}

func isSwap(qc *queryContext, pred1SubjectUid uint64, pred1Predicate string) (bool, error) {
	for i := range qc.uniqueVars {

Review comment (suggestion):
same here
```
if qc.gmuList[gmuIndex2].Set == nil {
    continue
}
```

Code after:
	if op.DropAll || op.DropOp == api.Operation_ALL {
		return true
	}
	return false
}

func verifyUniqueWithinMutation(qc *queryContext) error {
	if len(qc.uniqueVars) == 0 {
		return nil
	}

	for i := range qc.uniqueVars {
		gmuIndex, rdfIndex := decodeIndex(i)
		// handles cases where the mutation was pruned in updateMutations
		if gmuIndex >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex] == nil || rdfIndex >= uint32(len(qc.gmuList[gmuIndex].Set)) {
			continue
		}
		pred1 := qc.gmuList[gmuIndex].Set[rdfIndex]
		pred1Value := dql.TypeValFrom(pred1.ObjectValue).Value
		for j := range qc.uniqueVars {
			if i == j {
				continue
			}
			gmuIndex2, rdfIndex2 := decodeIndex(j)
			// check for the second predicate, which could also have been pruned
			if gmuIndex2 >= uint32(len(qc.gmuList)) || qc.gmuList[gmuIndex2] == nil || rdfIndex2 >= uint32(len(qc.gmuList[gmuIndex2].Set)) {
				continue
			}
			pred2 := qc.gmuList[gmuIndex2].Set[rdfIndex2]
			if pred2.Predicate == pred1.Predicate && dql.TypeValFrom(pred2.ObjectValue).Value == pred1Value &&
				pred2.Subject != pred1.Subject {
				return errors.Errorf("could not insert duplicate value [%v] for predicate [%v]",
					pred1Value, pred1.Predicate)
			}
		}
	}
	return nil
}

func isUpsertCondTrue(qc *queryContext, gmuIndex int) bool {
	condVar := qc.condVars[gmuIndex]
	if condVar == "" {
		return true
	}

	uids, ok := qc.uidRes[condVar]
	return ok && len(uids) == 1
}

func isSwap(qc *queryContext, pred1SubjectUid uint64, pred1Predicate string) (bool, error) {
	for i := range qc.uniqueVars {