- Notifications
You must be signed in to change notification settings - Fork 11
Description
Observed behavior
When a targetingKey
is set on an OpenAPIClient, a subsequent context passed via any of the get[...]Details/Value functions is not being correctly merged and the requested flagKey
is evaluated with the context set initially.
Expected Behavior
When a targetingKey
is passed as $context
for flag evaluation via any of the get[...]Details/Value functions, it should updated a previously set client context. The requested flagKey
should then be evaluated with the updated context.
Steps to reproduce
To reproduce, we can consider a simple targetingKey-test
flag definition in a flags.json
file.
{ "flags": { "targetingKey-test": { "state": "ENABLED", "variants": { "false": false, "true": true }, "targeting": { "if": [ {"in": [ {"var": "targetingKey"}, ["correct_key"] ] }, false] }, "defaultVariant": "true" } }
We can then build a new OpenAPIClient and pass it a default string context.
use GuzzleHttp\Client; use OpenFeature\OpenFeatureAPI; use OpenFeature\OpenFeatureClient; use OpenFeature\Providers\Flagd\FlagdProvider; use OpenFeature\Providers\Flagd\config\HttpConfig; use OpenFeature\implementation\flags\MutableEvaluationContext; $api = OpenFeatureAPI::getInstance(); $client = new Client(); $httpFactory = new HttpFactory(); $provider = new FlagdProvider( [ 'hostname' => 'localhost', 'port' => 8013, 'protocol' => 'http', 'secure' => false, 'httpConfig' => new HttpConfig( $client, $httpFactory, $httpFactory, ), ], ); $api->setProvider($provider); $apiClient = $api->getClient('test-client', '1.0'); $apiClient->setEvaluationContext(new MutableEvaluationContext("default"));
We can perform the targetingKey-test
evaluation by passing a targetingKey directly in the getBooleanDetails() function.
$flagKey = "targetingKey-test"; $defaultValue = "true"; $updatedContext = new MutableEvaluationContext($targetingKey); $details = $apiClient->getBooleanDetails($flagKey, $defaultValue, $updatedContext);
We can finally inspect the contents of $details
.
var_dump($details);
In the output, we can observe that the value
field of the EvaluationDetails object is set to bool(true), whilst it should be set to bool(false).