Inserting zero on integer with golang dgo client, inserts null instead


Report a Dgraph Client Bug

Here is my type:

type PersonGraphQL struct {
	Uid     string   `json:"uid,omitempty"`
	Name    string   `json:"Person.name,omitempty"`
	Private bool     `json:"Person.private,omitempty"`
	Pos     int      `json:"Person.pos,omitempty"`
	DType   []string `json:"dgraph.type,omitempty"`
}

Here is the data:

u := PersonGraphQL{
		Name:    "Pam",
		Private: true,
		Pos:     0,
		DType:   []string{"Person"},
	}

Transaction response:

txn:<start_ts:171189 commit_ts:171190 preds:"1-0-Person.name" preds:"1-0-Person.private" preds:"1-0-dgraph.type" > latency:<parsing_ns:45926 processing_ns:2903364 assign_timestamp_ns:1421681 total_ns:4467336 > metrics:<num_uids:<key:"_total" value:4 > num_uids:<key:"mutation_cost" value:4 > > uids:<key:"dg.1162310994.407" value:"0x13a28" > hdrs:<key:"content-type" value:<value:"application/grpc" > > hdrs:<key:"dgraph-toucheduids" value:<value:"4" > >

GraphQL query response:

      {
        "name": "Pam",
        "private": true,
        "pos": null
      }

Pos should be 0.

What Dgraph client (and version) are you using?

(put “x” in the box to select)

  • Dgo

Version:
Latest

What version of Dgraph are you using?

Latest

Expected behaviour and actual result.

mutation MPerson {
  addPerson(input: {name: "po", private: true, pos: 0}){
    person {
      name
      private
      pos
    }
  }
}

GraphQL result:

 {
        "name": "po",
        "private": true,
        "pos": 0
      },

Golang should be inserting 0 instead of null.

0 is a zero value in go, and your struct has the tag: omitempty which means “do not render this to json if it’s a zero value”, so you are not sending 0 to dgraph. Remove the struct tag and try again.

I suggest you use some other inserting mechanism with dgo like the protobuf API - which has far fewer caveats.

the tag: omitempty which means “do not render this to json if it’s a zero value”

Did not know that. Many thanks for letting me know.

I suggest you use some other inserting mechanism with dgo like the protobuf API

Will do!

Thanks for your time!