Skip to content

Conversation

@bdchauvette
Copy link
Contributor

This commit updates Flagsmith::Flags::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.

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.
@bdchauvette
Copy link
Contributor Author

I looked into writing tests for this, but I didn't see an easy way to write one without impacting other tests by adding a new fixture 😬

Happy to add a new fixture or an explicit test, though!

@zachaysan zachaysan merged commit 3e0d42c into Flagsmith:main Dec 4, 2024
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 this pull request may close these issues.

2 participants