Stale field data. Bug?


Couchbase 4.0 CE
Golang 1.6.2, Mac OS
gocb driver - last go get -u from July 8, 2016.

I have 2 records. The only difference between them is that the 1st one has a field “imageFull” while the 2nd one does not have this field.

I’m doing a regular loop over the n1ql results as per

var row MyStruct
for rows.Next(&row) {


A record with a missing “imageFull” field (at least as per Query Workbench) , still contains this field with a value from a previous record.

Please advise.

Hey @dennis,

This is due to the behaviour of Go’s JSON decoder. It only will modify fields which actually exist within the JSON. Because you are reusing your row through multiple passes, and later versions of the JSON do not contain your imageFull field, that field is not being touched. The solution is relatively simple (just reset the structure after each row):

var row MyStruct
for rows.Next(&row) {
  row = MyStruct{}

Cheers, Brett


That worked!

Thanks so much,