If you suspect this could be a bug, follow the template.
What version of Dgraph are you using?
currently i'm using dgraph version 1.0.0
Have you tried reproducing the issue with latest release?
yes i have tried it, in old and new dgraph version
old version ran smoothly (0.7.x) (0.8.x)
after (0.9.2) release, it couldn't create the node (got an error)
then (1.0.0) came out and the result seems wrong
What is the hardware spec (RAM, OS)?
RAM 8GB, OS Ubuntu 16.04
Steps to reproduce the issue (command/config used to run Dgraph).
c := client.NewDgraphClient(api.NewDgraphClient(conf.Key.Dgraph.Connection))
p := PersonEdit{
Uid: "0xa14222b693e4ba34",
Name: "Name",
Age: 26,
Married: true,
Location: "Jakarta",
Friend: []Friend{
{
Name: "Bob",
Age: 24,
LastUpdateTime: time.Now(),
ReadStatus: 1,
},
},
School: []School{
{
Name: "Crown Public School",
},
},
}
protosMutation := &api.Mutation{
CommitNow: true,
}
byteData, err := json.Marshal(p)
if err != nil {
log.Println(err)
}
protosMutation.SetJson = byteData
newAction := c.NewTxn()
ctx := context.Background()
defer newAction.Discard(ctx)
node, err := newAction.Mutate(ctx, protosMutation)
if err != nil {
log.Println(err)
}
Actual result:
Custom UID: 0xa14222b693e4ba34
Byte data: {"uid":"0xa14222b693e4ba34","name":"Name","age":26,"married":true,"following":[{"name":"Bob","age":24,"following|read_status":1,"following|last_update_time":"2017-12-19T20:04:52.321873602+07:00"}],"loc":"Jakarta","school":[{"uid":"","name@en":"Crown Public School","school:since":"0001-01-01T00:00:00Z"}]}
2017/12/19 20:04:52 map[blank-0:0x18 blank-1:0x19 blank-2:0x1a]
I have been investigating this issue. The issue is that we silently fail if we can't parse a uid as uint64. So 0xa14222b693e4ba34 in this case can't be parsed as uint64 but we don't return the error to the user and instead assign a new uid. We should return an error in this case.
it seems that's the problem, i tried to parse it to uint64 also, the result's failed.
Actually the custom uid that i generated is an uint64. i changed the value using fmt.Sprintf("0x%x", customUID)
after see this, i tried to insert it with raw uint64, the value is 11619888156129933876
using fmt.Sprintf("%v", customUID), then i tried to parse it and it seems okay
but the result from dgraph looks the same as before,
uint64: 11619888156129933876
Custom UID: 11619888156129933876 //0xa14222b693e4ba34
Parsing: 11619888156129933876
Byte data: {"uid":"11619888156129933876","name":"Name","age":26,"married":true,"following":[{"name":"Bob","age":24,"following|read_status":1,"following|last_update_time":"2017-12-19T20:57:26.488109045+07:00"}],"loc":"Jakarta","school":[{"uid":"","name@en":"Crown Public School","school:since":"0001-01-01T00:00:00Z"}]}
2017/12/19 20:57:26 map[blank-2:0x22 blank-0:0x23 blank-1:0x21]
maybe my custom uid isn't allowed anymore in dgraph?
btw i tried to use the example code from google docs
and i got this error rpc error: code = Unknown desc = Uid: [1000] cannot be greater than lease: [0]
code that i used:
conn, err := grpc.Dial("127.0.0.1:9080", grpc.WithInsecure())
if err != nil {
log.Fatal("While trying to dial gRPC")
}
defer conn.Close()
dc := api.NewDgraphClient(conn)
dg := client.NewDgraphClient(dc)
// In this test we check S * * deletion.
type Person struct {
Uid string `json:"uid,omitempty"`
Name string `json:"name,omitempty"`
Age int `json:"age,omitempty"`
Married bool `json:"married,omitempty"`
Friends []*Person `json:"friend,omitempty"`
}
p := Person{
Uid: "1000",
Name: "Alice",
Age: 26,
Married: true,
Friends: []*Person{&Person{
Uid: "1001",
Name: "Bob",
Age: 24,
}, &Person{
Uid: "1002",
Name: "Charlie",
Age: 29,
}},
}
op := &api.Operation{}
op.Schema = `
age: int .
married: bool .
`
ctx := context.Background()
err = dg.Alter(ctx, op)
if err != nil {
log.Fatal(err)
}
mu := &api.Mutation{
CommitNow: true,
}
pb, err := json.Marshal(p)
if err != nil {
log.Fatal(err)
}
mu.SetJson = pb
_, err = dg.NewTxn().Mutate(ctx, mu)
if err != nil {
log.Fatal(err)
}
Hey @Harfondy
I would like to clarify that you cant set custom ids in Dgraph. You can only set an id which was returned by Dgraph.
rpc error: code = Unknown desc = Uid: [1000] cannot be greater than lease: [0]
Dgraph maintains a lease which is the max id that was allocated, so the id you set can't be greater then that. I will update the example to make it more clear.
I have merged a fix in e9865185205aa8293eb64cacf6e350aa5ed28ca1. An error would be returned if we can't parse the uid as uint64. Also, updated the examples in GoDoc.
@pawanrawal how to link two same entities, like two people in the same company, it seems that there are two nodes representing the same company with different uid, if custom uid then there will be only one node? much thanks
Most helpful comment
@pawanrawal how to link two same entities, like two people in the same company, it seems that there are two nodes representing the same company with different uid, if custom uid then there will be only one node? much thanks