Skip to content

[BUG] InMemoryProvider returns error if variant is not found #603

@kylejuliandev

Description

@kylejuliandev

Observed behavior

The InMemoryProvider allows you to specify a contextEvaluator which you can use to dynamically pick or chose the variant the InMemoryProvider returns based on the context. Consider an InMemoryFlag that will return two possible variants from the contextEvaluator:

{
    "boolean-targeted-zero-flag": {
        "contextEvaluator": "email == '[email protected]' ? 'zero' : ''",
        "defaultVariant": "zero",
        "variants": {
            "non-zero": true,
            "zero": false
        }
    }
}

If the predicate returns false, we get a variant of "" which is not registered as a variant for the flag.

var variant = this._contextEvaluator.Invoke(evaluationContext ?? EvaluationContext.Empty);
if (!this._variants.TryGetValue(variant, out value))
{
throw new GeneralException($"variant {variant} not found");
}

This causes OpenFeature to return the an error, meaning the API returns the default parameter as provided to the client. It does not return the default variant as configured in the provider.

var result = await client.GetBooleanDetailsAsync("boolean-targeted-zero-flag", false)

This result will be false, however the InMemoryProvider is configured to return the default variant "zero" which is true.

Expected Behavior

I found this while adding the remaining e2e tests as described in the specification. Specifically, the Null context values scenario and the Empty evaluation context scenario.

These e2e test cases expect the default variant, as configured by the InMemoryProvider, to be returned. Not the default value provided to the client when evaluating the flag.

var result = await client.GetBooleanDetailsAsync("boolean-targeted-zero-flag", false)

The result is expected to return true, but instead returns false when configured with the boolean-targeted-zero-flag flag above.

The Java SDK handles this as expected in the gherkin file.

Steps to reproduce

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: sdkThis issue or pull request relates to an SDKtype: bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions