Skip to content

[BUG] FILE resolver type falls back to default value #213

Closed
@stepheniota

Description

@stepheniota

Description

When using the flagd provider with the FILE resolver type, the feature flag evaluation sometimes returns the default_value instead of the expected variant from our flags.json. For example, if you call .get_boolean_value() multiple times on the same flag name but with different default values, the client falls back to the default instead of returning the configured variant.

Sample code

Sample flags.json:

{
    "$schema": "https://flagd.dev/schema/v0/flags.json",
    "flags": {
        "enable-debug-logs": {
            "defaultVariant": "custom_key",
            "state": "ENABLED",
            "targeting": {
                "if": [
                    {
                        "in": [
                            {
                                "var": "instance"
                            },
                            [
                                "placeholder",
                                "custom_key"
                            ]
                        ]
                    },
                    {
                        "var": "instance"
                    },
                    null
                ]
            },
            "variants": {
                "placeholder": true,
                "custom_key": false
            }
        }
    }
}

Sample code:

from openfeature import api
from openfeature.contrib.provider.flagd import FlagdProvider
from openfeature.contrib.provider.flagd.config import ResolverType
from openfeature.evaluation_context import EvaluationContext

evaluation_ctx = EvaluationContext(
    targeting_key="instance",
    attributes={
        "instance": "custom_key",
    },
)

api.set_evaluation_context(evaluation_ctx)
api.set_provider(
    FlagdProvider(
        resolver_type=ResolverType.FILE,
        offline_flag_source_path="flags.json",
    )
)

client = api.get_client()

print(client.get_boolean_value("enable-debug-logs", default_value=False))
print(client.get_boolean_value("enable-debug-logs", default_value=True))

You should see the output:

False
True

which means the default_value was returned.

Environment details

Python 3.11.11
openfeature-provider-flagd==0.2.0
openfeature_sdk==0.8.0

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