aerospike / aerospike-client-go

Aerospike Client Go
Apache License 2.0
433 stars 199 forks source link

[Bug] GetObject or any reflect Get operation failing for a struct inside a struct for all omitempty fields. #301

Closed kartavya-ramnani closed 4 years ago

kartavya-ramnani commented 4 years ago

If there a struct inside a struct which has fields with omitempty tag, that field NEVER gets fetched.

For example :

struct A { Bstruct B as:"b" }

struct B { Test string as:"test,omitempty" // this will never be returned in any read reflection commands }

Reason :

Inside read_command_reflect.go : setStructValue : alias will be Test Then this line comes :

tag := strings.Trim(fld.Tag.Get(aerospikeTag), " ")

and tag is test,omitempty so alias becomes test,omitempty

And valMap[alias] will fail.

This is a major bug in my opinion and I can really use help in getting this fixed asap.

kartavya-ramnani commented 4 years ago

What needs to be fixed : Replace in read_command_reflect.go -> setStructValue :

tag := strings.Trim(fld.Tag.Get(aerospikeTag), " ")

with

tag := strings.Trim(stripOptions(fld.Tag.Get(aerospikeTag)), " ")
kartavya-ramnani commented 4 years ago

Commit which may have introduced this.

I guess, before introducing the omitempty tag, this must be working fine but after introducing omitempty tag with 2.8.0 , this bug crept in..

Any way we can fix this asap? It is a one-line code change.

khaf commented 4 years ago

I tried to fix it today, but this issue turned out to be related to a bigger problem that I have to address. Will release the fix next week.

kartavya-ramnani commented 4 years ago

Can I ask what is the bigger problem ? @khaf We are using this library on high production traffic.

khaf commented 4 years ago

The PR that introduced this bug introduced another regression that tests didn't catch, and now I have to find a way to fix it in a way that is backwards compatible without breaking the internet.

kartavya-ramnani commented 4 years ago

Hi @khaf : Is this fixed ?

khaf commented 4 years ago

Not yet; I'm now considering releasing a quick fix for you and spend a bit more time for the other one.

kartavya-ramnani commented 4 years ago

@khaf : Will appreciate it if you do that.

khaf commented 4 years ago

Fix released in v3.0.1. Thank you for your patience.