Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in local evaluation of feature flags without multivariates when calling GetFeatureFlag #77

Open
dpovey opened this issue Oct 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@dpovey
Copy link

dpovey commented Oct 13, 2024

I have a boolean flag that is defined with filters with seperate rollout percentages.

Here is a rough structure of the flag

flag posthog.FeatureFlag = {
  Key = ...
  IsSimpleFlag = false
  RolloutPercentage = nil
  Active = true
  Filters = {
    AggregationGroupTypeIndex = nil
    Groups = [
        { 
            Properties = ...
            RolloutPercentage = 50
            Variant = nil
        },
        ...
    ],
    Multivariate = nil,
   Payloads = {}
   }
   EnsureExperienceContinuity = false
  }

I can see that my condition matches in matchFeatureFlagProperties, but in the processing of this code:

if isMatch {
  		variantOverride := condition.Variant
  		multivariates := flag.Filters.Multivariate

  		if variantOverride != nil && multivariates != nil && multivariates.Variants != nil && containsVariant(multivariates.Variants, *variantOverride) {
  			return *variantOverride, nil
  		} else {
  			return getMatchingVariant(flag, distinctId)
  		}
  	}

It doesn't correctly handle the case where there are no variants. It calls getMatchingVariant when it could just cal checkIfSimpleFlagEnabled like so:

                if isMatch {
			variantOverride := condition.Variant
			multivariates := flag.Filters.Multivariate

			if variantOverride != nil && multivariates != nil && multivariates.Variants != nil && containsVariant(multivariates.Variants, *variantOverride) {
				return *variantOverride, nil
			} else if multivariates == nil || multivariates.Variants == nil || len(multivariates.Variants) == 0 {
				// Handle boolean flag with condition-specific rollout percentage
				if condition.RolloutPercentage != nil {
					return checkIfSimpleFlagEnabled(flag.Key, distinctId, *condition.RolloutPercentage)
				}
				return true, nil
			} else {
				return getMatchingVariant(flag, distinctId)
			}
		}

Or perhaps some variation that has a different salt. This is preventing me being able to use Posthog as I need to be able to locally evaluate these flags.

@dmarticus dmarticus added the bug Something isn't working label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants