Skip to content

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

@JoSuzuki

Description

@JoSuzuki

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

  • Create feature_flag_A with 4 variations
  • Create feature_flag_B with two variations
  • Make feature_flag_A with variation of index 2 a prerequisite of feature_flag_B
  • When starting the app with those feature flags the error will appear as ERROR -- : [LDClient] Data inconsistency in feature flag "feature_flag_B": prerequisite has invalid variation index.

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

Prerequisite.new(prereq_data, self, errors)

There will be a prerequisite {:key=>"feature_flag_A", :variation=>2}, which will create a Prerequisite
class Prerequisite
def initialize(data, flag, errors_out = nil)
@data = data
@key = data[:key]
@variation = data[:variation]
@failure_result = EvaluatorHelpers.evaluation_detail_for_off_variation(flag,
EvaluationReason::prerequisite_failed(@key))
check_variation_range(flag, errors_out, @variation, "prerequisite")
end

and call check_variation_range
def check_variation_range(flag, errors_out, variation, description)
unless flag.nil? || errors_out.nil? || variation.nil?
if variation < 0 || variation >= flag.variations.length
errors_out << "#{description} has invalid variation index"
end
end
end

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions