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

Bugfix: Set found to false to avoid deleting index edge when value doesn't match. #3843

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 19 additions & 2 deletions dgraph/cmd/alpha/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,14 +1294,15 @@ func TestDeleteAllSP2(t *testing.T) {
}

func TestDeleteScalarValue(t *testing.T) {
var s = `name: string .`
var s = `name: string @index(exact) .`
require.NoError(t, schema.ParseBytes([]byte(""), 1))
require.NoError(t, alterSchemaWithRetry(s))

var m = `
{
set {
<0x12345> <name> "xxx" .
<0x12345> <name> "xxx" .
<0x12346> <name> "xxx" .
}
}
`
Expand Down Expand Up @@ -1342,6 +1343,17 @@ func TestDeleteScalarValue(t *testing.T) {
require.NoError(t, err)
require.JSONEq(t, `{"data": {"me":[{"name":"xxx"}]}}`, output)

indexQuery := `
{
me(func: eq(name, "xxx")) {
name
}
}
`
output, err = runGraphqlQuery(indexQuery)
require.NoError(t, err)
require.JSONEq(t, `{"data": {"me":[{"name":"xxx"}, {"name":"xxx"}]}}`, output)

var d2 = `
{
delete {
Expand All @@ -1356,6 +1368,11 @@ func TestDeleteScalarValue(t *testing.T) {
output, err = runGraphqlQuery(q)
require.NoError(t, err)
require.JSONEq(t, `{"data": {"me":[]}}`, output)

// Verify index was also updated this time and one of the triples got deleted.
output, err = runGraphqlQuery(indexQuery)
require.NoError(t, err)
require.JSONEq(t, `{"data": {"me":[{"name": "xxx"}]}}`, output)
}

func TestDeleteValueLang(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion posting/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (txn *Txn) addMutationHelper(ctx context.Context, l *List, doUpdateIndex bo

if pFound && !(bytes.Equal(currPost.Value, newPost.Value) &&
types.TypeID(currPost.ValType) == types.TypeID(newPost.ValType)) {
return val, found, emptyCountParams, err
return val, false, emptyCountParams, nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth adding part of the comment from your PR description here just to help future readers of the code have that context? Otherwise it sticks out a little bit because every where else you return the found variable.

}
}

Expand Down