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

1-to-1 relation overwrite in transaction doesn't work anymore. #5017

Closed
emile-tawfik opened this issue Mar 24, 2020 · 2 comments
Closed

1-to-1 relation overwrite in transaction doesn't work anymore. #5017

emile-tawfik opened this issue Mar 24, 2020 · 2 comments
Labels
kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate/work on it.

Comments

@emile-tawfik
Copy link

The issue

In v1.1.x with introduction of single relations, the only way to overwrite a single relation was to use multiple mutation in single transaction (delete + insert) (#4136).
However, it seems this method doesn't work anymore since v1.2.2 because of a bug.

What version of Dgraph are you using?

The issue exists on v1.2.2 and master.
The issue doesn't exist on v1.2.1

Steps to reproduce the issue (command/config used to run Dgraph).

There is a test I wrote to reproduce the issue. I added it in query/query4_test.go.

func TestOverwriteOneToOneRelationInATransaction(t *testing.T) {
	schema := `
		onetoonerel: uid .
		data: int .
	`
	setSchema(schema)

	triples := `
		_:node1 <onetoonerel> _:node2 .
		_:node2 <data> "42" .
	`
	resp, err := client.NewTxn().Mutate(context.Background(), &api.Mutation{
		SetNquads: []byte(triples),
		CommitNow: true,
	})
	require.NoError(t, err)

	node1Uid := resp.Uids["node1"]
	node2Uid := resp.Uids["node2"]

	txn := client.NewTxn()

	_, err = txn.Mutate(context.Background(), &api.Mutation{
		DelNquads: []byte(fmt.Sprintf("<%s> <onetoonerel> <%s> .", node1Uid, node2Uid)),
	})
	require.NoError(t, err)

	resp, err = txn.Mutate(context.Background(), &api.Mutation{
		SetNquads: []byte(fmt.Sprintf(`<%s> <onetoonerel> _:node3 .
		_:node3 <data> "24" .`, node1Uid)),
	})
	require.NoError(t, err)

	node3Uid := resp.Uids["node3"]
	err = txn.Commit(context.Background())
	require.NoError(t, err)

	query := fmt.Sprintf(`{
		me(func:uid(%s)) {
			uid
			onetoonerel {
				uid
			}
		}
	}`, node1Uid)
	js := processQueryNoErr(t, query)
	require.JSONEq(t, fmt.Sprintf(`
	{
		"data": {
			"me": [
				{
					"uid": "%s",
					"onetoonerel": {
						"uid": "%s"
					}
				}
			]
		}
	}
	`, node1Uid, node3Uid), js)
}

Expected behaviour and actual result.

After a bisect it seems that the bug was introduced in cc495fc

Expected the test to pass.
Got:

--- FAIL: TestOverwriteOneToOneRelationInATransaction (1.07s)
    query4_test.go:1596: 
                Error Trace:    query4_test.go:1596
                Error:          Not equal: 
                                expected: map[string]interface {}{"data":map[string]interface {}{"me":[]interface {}{map[string]interface {}{"onetoonerel":map[string]interface {}{"uid":"0x186bf"}, "uid":"0x186bd"}}}}
                                actual  : map[string]interface {}{"data":map[string]interface {}{"me":[]interface {}{map[string]interface {}{"onetoonerel":map[string]interface {}{"uid":[]interface {}{"0x186be", "0x186bf"}}, "uid":"0x186bd"}}}}
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -5,3 +5,6 @@
                                     (string) (len=11) "onetoonerel": (map[string]interface {}) (len=1) {
                                -     (string) (len=3) "uid": (string) (len=7) "0x186bf"
                                +     (string) (len=3) "uid": ([]interface {}) (len=2) {
                                +      (string) (len=7) "0x186be",
                                +      (string) (len=7) "0x186bf"
                                +     }
                                     },
                Test:           TestOverwriteOneToOneRelationInATransaction
@shekarm shekarm added kind/bug Something is broken. status/needs-attention This issue needs more eyes on it, more investigation might be required before accepting/rejecting it labels Mar 26, 2020
@martinmr
Copy link
Contributor

I will look into this. But in version 1.2.2 you should be able to overwrite the value with a single set. Can you try doing just the set instead of delete+ set? You don't need the delete anymore. I'll check the documentation to see if that's been updated.

There are tests for this use case but I am guessing there are no tests for the old workflow (delete + add).

@martinmr martinmr added priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate/work on it. and removed status/needs-attention This issue needs more eyes on it, more investigation might be required before accepting/rejecting it labels Apr 30, 2020
@minhaj-shakeel
Copy link
Contributor

Github issues have been deprecated.
This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken. priority/P1 Serious issue that requires eventual attention (can wait a bit) status/accepted We accept to investigate/work on it.
Development

No branches or pull requests

4 participants