Hello, is there any known issue with the golang sd...
# announcements
f
Hello, is there any known issue with the golang sdk not evaluating number conditionals? strings seem to perform as expected but not ints, exp I have forceRule
version equal 10
Copy code
context := growthbook.NewContext().
		WithFeatures(featureMap).
		WithAttributes(growthbook.Attributes{
			"version": 10,
		})
	gb := growthbook.New(context)
    value := gb.Feature("featureName").Value
f
Hi David - I seem to remember a bug fix for this - are you on the latest version of the SDK?
f
no am on
v0.1.0
does
v0.1.3
have the fix?
f
we’ve done some work on the go SDK
you should update
b
@alert-dream-63361 do you know if this specific issue was addressed in an update after 0.1.0?
a
I've just been trying to duplicate this with the most recent version and with v0.1.0, and I can't make it happen in any version with any kind of condition in the feature rule. Conditions of the form
"version": 10
and
"version": { "$eq": 10 }
both seem to work fine. This might be a stupid question, but does the conditional value appear as an integer in the feature rule definition? If the condition is coming through as
"version": "10"
, then the Go SDK code won't work, because it requires the two values being compared to be the same type. String vs. int comparisons might be something we should be able to handle though, because I think the JS code will just quietly convert strings to ints for conversion there. What do you think, @better-magician-65629?
b
if the type is defined in the dashboard as a number type, it should appear numerically in the features JSON.
donut_price
is an example of a float doing that. https://cdn.growthbook.io/api/features/java_NsrWldWd5bxQJZftGsWKl7R2yD2LtAK8C8EUYh9L8 in the java SDK, what i'm doing to get around the types thing is, in one case, i am getting number types as float, and coercing the attribute to a float if it's a number type, and checking those. in another case, the JSON serialization library i'm using (gson) has a way to get the JSON primitive as a Number which supports equality checks across numeric types. @alert-dream-63361 not sure if it may be worth the effort to take a look at the go example and do some equality checks with the
donut_price
feature. i realized i didn't grab that attribute but it's there in the response (it's using the java_N.. url linked above)
a
I will do that tomorrow. It's a good idea to check it that way. I'll let you know what I find.
b
yeah no worries, have a good night 🌙 i've also been meaning to check your PR and hopefully can get to it today, thanks @alert-dream-63361
a
OK, I know what's going on here. When Go converts JSON values, it converts all the numeric values as floats. If you then try to compare with an integer, the comparison fails because the things are different types. I think that the correct way to handle this is to do all numeric comparisons with floats, which matches the semantics of the JS SDK. What do you think, @better-magician-65629? @full-pager-39100 As a quick workaround until we decide on a more permanent fix, you can make sure that the values in your attributes are floats, i.e.
Copy code
context := growthbook.NewContext().
		WithFeatures(featureMap).
		WithAttributes(growthbook.Attributes{
			"version": float64(10),
		})
	gb := growthbook.New(context)
    value := gb.Feature("featureName").Value
That will make the comparisons with the numeric values coming from the GrowthBook API work correctly.
b
which matches the semantics of the JS SDK
did you mean the java SDK? the JS SDK didn't have this challenge. but yeah, that's what i described above, so i think that should work for go as well.
👍 1
a
I did mean the JS SDK, just in the sense that the comparison semantics in JS mean that it's just not a problem that occurs, but your description of what you did for the Java SDK is pretty much exactly what I did for the Go code!
I've made a PR with a fix for this, and we can release that as v0.1.4. I'll pull those changes into my "JS SDK parity" working branch as well.
b
i looked at the code and approved, there's some conflicts from your other PR. once those are resolved we can merge