Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When feature's default value is false it returns nil instead #20

Closed
pokonski opened this issue May 4, 2023 · 3 comments · Fixed by #21
Closed

When feature's default value is false it returns nil instead #20

pokonski opened this issue May 4, 2023 · 3 comments · Fixed by #21

Comments

@pokonski
Copy link

pokonski commented May 4, 2023

Given a super simple feature defition:

{"defaultValue"=>false}

The SDK returns nil when checking its value, reproduction code:

features = {"simple_feature" => {"defaultValue" => false}}
gb = Growthbook::Context.new(features: features)
gb.on?("simple_feature") #=> false
gb.feature_value("simple_feature") #=> nil

Is this expected behaviour? The offending code is here: https://github.com/growthbook/growthbook-ruby/blob/main/lib/growthbook/context.rb#L137

Which I think is incorrect since: false || nil in Ruby will always yield nil. I think what author meant to write was:

feature.default_value.nil? ? nil : feature.default_value

I also tested the behaviour with JS SDK and it does return false as expected:

gb.loadFeatures({ autoRefresh: true }).then(function() {
	gb.getFeatureValue('simple_feature'); // => false
});
@pokonski
Copy link
Author

I can provide a PR with a fix if needed and you confirm this to be an issue :)

@jdorn
Copy link
Member

jdorn commented Jun 2, 2023

Thanks for catching this. A PR would be great!

@Rabshab
Copy link

Rabshab commented Jun 13, 2023

PR here

tinahollygb added a commit that referenced this issue Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants