configcat / ruby-sdk

ConfigCat SDK for Ruby. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/ruby
MIT License
12 stars 3 forks source link

Flag overrides parameter is not working in v6+ #25

Closed irwalker closed 1 year ago

irwalker commented 1 year ago

Describe the bug

Using the flag_overrides parameter on v6+ of this gem causes an error:

NoMethodError (undefined method `create_data_source' for #<ConfigCat::LocalDictionaryDataSource:0x00000001135fd020 @_override_behaviour=0, 
# removed our configuration details ...

      @_override_data_source = options.flag_overrides.create_data_source(@log)
                                                        ^^^^^^^^^^^^^^^^^^^):

To reproduce

Initialise a config cat client with the flag_overrides parameter set.

Failing spec: https://github.com/configcat/ruby-sdk/pull/26

Expected behavior

This used to override local feature flags when using offline settings. E.g:

flag_overrides = LocalDictionaryDataSource.new(
      { some_feature: "yes" },
      OverrideBehaviour::LOCAL_ONLY,
    )
    client = ConfigCatClient.get("test", ConfigCatOptions.new(flag_overrides: flag_overrides))
z4kn4fein commented 1 year ago

Hi @irwalker, thanks for reporting this issue! We started to work on the fix. I'll notify you when it's released.

z4kn4fein commented 1 year ago

Hi @irwalker, it turned out that the example test uses the wrong type for the local dictionary override definition. This is the correct one:

flag_overrides = LocalDictionaryFlagOverrides.new(
  { some_feature: "yes" },
  OverrideBehaviour::LOCAL_ONLY,
  )

So, instead of LocalDictionaryDataSource.new(), it must be LocalDictionaryFlagOverrides.new(). Did you find LocalDictionaryDataSource.new() in the docs or examples? I'm just asking because I'd also fix it there if that's the case.

irwalker commented 1 year ago

Thanks for the quick response on this @z4kn4fein!

Prior to 6.0 we were using ConfigCat::LocalDictionaryFlagOverrides.new which worked OK - the dev who implemented this in our system looked at the gem source to figure out which class to use.

Using LocalDictionaryFlagOverrides.new appears to have solved our problem.

Note that if I use LocalDictionaryFlagOverrides.new in our code prior to the 6.0 update it is not defined.

, [2023-06-21T16:52:36.958455 #42326] ERROR -- : #<NameError: uninitialized constant ConfigCat::LocalDictionaryFlagOverrides
ConfigCat::LocalDictionaryFlagOverrides.new(

Also, I just realised this was documented in the Changelog 🤦

irwalker commented 1 year ago

I'm going to mark this as closed since the change was mentioned in the Changelog; I think it would be better if there was a breaking changes section in release docs to make this more obvious in future releases 😄.

Thanks again for the quick response

z4kn4fein commented 1 year ago

Yeah, you're right, we'll do it that way next time. Thanks for the feedback!