launchdarkly / ruby-server-sdk

LaunchDarkly Server-side SDK for Ruby
https://docs.launchdarkly.com/sdk/server-side/ruby
Other
34 stars 50 forks source link

Flags with prerequisites `check_variation_range` compares the range for the flag's variations instead of the prerequisite's flag variations. #260

Closed JoSuzuki closed 5 months ago

JoSuzuki commented 5 months ago

Describe the bug When starting an app with the launchdarkly-server-sdk I get the following error:

I, [2024-03-20T13:20:56.879571 #2115]  INFO -- : [LDClient] Initializing stream connection
I, [2024-03-20T13:20:56.883992 #2115]  INFO -- : Connecting to event stream at https://stream.launchdarkly.com/all
E, [2024-03-20T13:20:57.472795 #2115] ERROR -- : [LDClient] Data inconsistency in feature flag "feature_flag_B": prerequisite has invalid variation index
I, [2024-03-20T13:20:57.479488 #2115]  INFO -- : [LDClient] Stream initialized

feature_flag_B has a prerequisite feature_flag_A on variation 2 (live) feature_flag_A has 4 variations [off , onboarding, live, offboarding]

To reproduce

Expected behavior When starting the app no error is logged.

SDK version 7.2.0

Language version, developer tools ruby 3.2.2

OS/platform Ubuntu 22.04

Additional context I believe the code path followed to get the error is: When creating the feature_flag_B at https://github.com/launchdarkly/ruby-server-sdk/blob/389953b477a241cbfd0694a5516a1e39ebf9c7ee/lib/ldclient-rb/impl/model/feature_flag.rb#L40 There will be a prerequisite {:key=>"feature_flag_A", :variation=>2}, which will create a Prerequisite https://github.com/launchdarkly/ruby-server-sdk/blob/389953b477a241cbfd0694a5516a1e39ebf9c7ee/lib/ldclient-rb/impl/model/feature_flag.rb#L120-L128 and call check_variation_range https://github.com/launchdarkly/ruby-server-sdk/blob/389953b477a241cbfd0694a5516a1e39ebf9c7ee/lib/ldclient-rb/impl/model/feature_flag.rb#L7-L13 Which compares the feature_flag_B.variations.length with feature_flag_A prerequisite variation 2. I believe the intended action would be to compare the feature_flag_A.variations.length instead.

keelerm84 commented 5 months ago

Sorry for the delay on this. This has been fixed in 7.3.3

JoSuzuki commented 5 months ago

Sorry for the delay on this. This has been fixed in 7.3.3

Thank you!