Skip to content

Commit 0a7abb3

Browse files
committed
fix: allow false as a flag value
This commit updates Flag#from_api to support `false` as a valid value. Previously, `false` values for `:feature_state_value` would would fall through the `||` branch and end up using the value from `:value`, which in most (all?) cases seems to be `nil`. The previous behavior made it impossible to distinguish between the following two cases: - an enabled flag that has never had its value set (and should therefore be treated as `true`) - an enabled flag that is explicitly set to `false` (and should therefore be treated as `false`) With the change in this commit, the first case will be `nil`, and the second case would be `false`. The `:value` key will now only be consulted when there is no `:feature_state_value` key present in the JSON flag data.
1 parent 046644f commit 0a7abb3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/flagsmith/sdk/models/flags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def from_feature_state_model(feature_state_model, identity_id)
7171
def from_api(json_flag_data)
7272
new(
7373
enabled: json_flag_data[:enabled],
74-
value: json_flag_data[:feature_state_value] || json_flag_data[:value],
74+
value: json_flag_data.fetch(:feature_state_value) { json_flag_data[:value] },
7575
feature_name: json_flag_data.dig(:feature, :name),
7676
feature_id: json_flag_data.dig(:feature, :id)
7777
)

0 commit comments

Comments
 (0)