Mutate: rpc error: code = Unknown desc = Empty query

Moved from GitHub dgo/82

Posted by jawr:

Hi there!

I have been trying to play with Dgraph but am having issues inserting data. I am using docker-compose as described in ‘Get started’. Following examples using curl for setting and retrieving data work.

Here is the relevant code below:

type Record struct {
        Uid string `json:"uid,omitempty"`
        Name string `json:"name,omitempty"`
        Type uint16 `json:"type,omitempty"`
        Class uint16 `json:"class,omitempty"`
        Ttl uint32 `json:"ttl,omitempty"`
        Original string  `json:"original,omitempty"`
}

func addRecord(client *dgo.Dgraph, rr dns.RR) error {
        var record Record

        record.Name = header.Name
        record.Type = header.Rrtype
        record.Class = header.Class
        record.Ttl = header.Ttl
        record.Original = header.String()

        ctx := context.Background()

        data, err := json.Marshal(record)
        if err != nil {
                return errors.Wrap(err, "Marshal")
        }

        mu := &api.Mutation{
                CommitNow: true,
                SetJson: data,
        }

        tx := client.NewTxn()
        defer tx.Discard(ctx)

        log.Printf("%+v", mu)
       // prints: set_json:"{\"name\":\"COM.\",\"type\":2,\"class\":1,\"ttl\":172800,\"original\":\"COM.\\t172800\\tIN\\tNS\\t\"}" commit_now:true

        _, err = tx.Mutate(ctx, mu)
        if err != nil {
                return errors.Wrap(err, "Mutate")
                // err == "rpc error: code = Unknown desc = Empty query"
        }

        err = tx.Commit(ctx)
        if err != nil {
                return errors.Wrap(err, "Commit")
        }

        return nil
}

the output for this is:

2019/08/24 15:31:43 set_json:"{\"name\":\"COM.\",\"type\":2,\"class\":1,\"ttl\":172800,\"original\":\"COM.\\t172800\\tIN\\tNS\\t\"}" commit_now:true 
2019/08/24 15:31:43 Error in add record at count 2: Mutate: rpc error: code = Unknown desc = Empty query

Thank you for your time.

bgv commented :

Which versions of dgraph and dgo are you running?

I had the same problem with dgraph v1.1.0-rc1 and when tried using it with dgo v2.

Try using dgraph v1.1.0-rc2 with github.com/dgraph-io/dgo/v2 otherwise use dgraph v1.1.0-rc1 with github.com/dgraph-io/dgo only.

jawr commented :

The version mismatch was exactly it, thank you for the help @bgv !