Dgraph version : v1.1.0
Dgraph SHA-256 : 7d4294a80f74692695467e2cf17f74648c18087ed7057d798f40e1d3a31d2095
Commit SHA-1 : ef7cdb28
Commit timestamp : 2019-09-04 00:12:51 -0700
Branch : HEAD
Go version : go1.12.7
I think that's the latest one.
Ubuntu 16.04, 16GB, don't think it's relevant here.
run dgraph 1.1.0
clone this branch of this repo:
https://github.com/uprtcl/js-uprtcl-server/tree/duplicated-heads
npm install
npm test
I configured the Perspective type as having one property called head of type uid (not [uid]). Check src/db/schema.ts and /src/db/dgraph.service.ts/
Since this issue was closed and added to V1.1.0, I expect that every time I set the head of a perspective the value is overwritten instead of added to the previous one.
In the last console.log there should be one single head edge. Instead, there are two.
[DGRAPH] getPerspectiveHead {
query: 'query {\n' +
' perspective(func: eq(xid, zb2wwruCksbXqsGYMVHZsFi6TcWWW7rNTnerJN2RBzE5ZecDU)) {\n' +
' head {\n' +
' xid\n' +
' }\n' +
' }\n' +
' }'
} { perspective: [ { head: [Array] } ] } {
head: [
{ xid: 'zb2wwzqMtQFTuvXWtQGQchSCzfAjE4GEWJby3wxbRTabjnTkb' },
{ xid: 'zb2wwyEFUzAAdf7ww8FqGVorGhwgf5fejhSmdVw1vd2aZuRuC' }
]
}
I think you've just defined the type schema. Dgraph won't check the type schema, you have to add in https://github.com/uprtcl/js-uprtcl-server/blob/05a19237417d7115e7457defe6d143e27a5cf8fb/src/db/schema.ts#L63 this:
head: uid .
Yeah, could you give us the result of running the following query?
schema {}
OK, I was able to reproduce the issue and I have a workaround for you.
The problem is that you didn't declare the head predicate in the Dgraph schema, you just created it as a field in the type Perspective.
This means Dgraph doesn't know about the head predicate at all! So when you create some data with a head predicate, Dgraph defaults to the [uid] type as it's supposed to.
So, in your case you should definitely add the following line to your schema:
<head>: uid .
This will enforce having the 1:1 relationship you wanted.
Additionally, if you want to avoid this behavior in the future and make sure no predicates are created without your permission, you should definitely protect the database by running your alphas with the --mutations=strict flag on.
$ dgraph alpha --help | grep mutations
--mutations string Set mutation mode to allow, disallow, or strict. (default "allow")
That will stop any mutations that don't follow the schema.
Finally, there's the question of whether the predicate should be created once we see it on a type.
I do think so, so I created #4085 to track it.
Thanks for the report!
Closing this issue now, feel free to reopen if there's anything else I missed.