Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This matrix mirrors the [feature matrix of the OpenFeature SDK for Python](https
| ✅ | Transaction Context Propagation | Provided by the OpenFeature SDK, which merges the transaction context into the evaluation context before the provider is called; no provider support is required. |
| ✅ | Extending | The underlying LaunchDarkly client is available through the `client` property. |
| ✅ | Flag metadata | LaunchDarkly evaluation reason details are returned as OpenFeature flag metadata. See [Flag Metadata](#flag-metadata). |
| ✅ | Override-affected metadata | `overrideAffected: True` is included in flag metadata only when an override affected the evaluation, directly or indirectly. Requires LaunchDarkly Python SDK 9.21.0 or later. |

<sub>Supported: ✅ | Partially supported: ⚠️ | Not supported: ❌</sub>

Expand Down Expand Up @@ -175,6 +176,7 @@ Evaluations include flag metadata for the LaunchDarkly specific parts of the eva
|---------------------|---------|-------------------------------------------------------------------|
| `variationIndex` | integer | The index of the returned variation. Absent for default values. |
| `inExperiment` | boolean | Present, and `True`, when the evaluation was part of an experiment.|
| `overrideAffected` | boolean | Present, and `True`, when an override affected the evaluation. |
| `ruleIndex` | integer | The index of the rule that matched. |
| `ruleId` | string | The identifier of the rule that matched. |
| `prerequisiteKey` | string | The key of the prerequisite flag that failed. |
Expand Down
4 changes: 4 additions & 0 deletions ld_openfeature/impl/details_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

_VARIATION_INDEX_KEY = 'variationIndex'
_IN_EXPERIMENT_KEY = 'inExperiment'
_OVERRIDE_AFFECTED_KEY = 'overrideAffected'
_RULE_INDEX_KEY = 'ruleIndex'
_RULE_ID_KEY = 'ruleId'
_PREREQUISITE_KEY_KEY = 'prerequisiteKey'
Expand Down Expand Up @@ -55,6 +56,9 @@ def __to_flag_metadata(reason: Mapping[str, Any], variation_index: Optional[int]
if reason.get('inExperiment') is True:
metadata[_IN_EXPERIMENT_KEY] = True

if reason.get('overrideAffected') is True:
metadata[_OVERRIDE_AFFECTED_KEY] = True

rule_index = reason.get('ruleIndex')
if isinstance(rule_index, int):
metadata[_RULE_INDEX_KEY] = rule_index
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ packages = [
[tool.poetry.dependencies]
python = "^3.10"
openfeature-sdk = ">=0.9.0,<1"
launchdarkly-server-sdk = ">=9.18.3,<10"
launchdarkly-server-sdk = ">=9.21.0,<10"


[tool.poetry.group.dev.dependencies]
Expand Down
14 changes: 14 additions & 0 deletions tests/impl/test_details_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ def test_flag_metadata_omits_in_experiment_for_non_experiment_evaluations(detail
assert 'inExperiment' not in resolution_details.flag_metadata


@pytest.mark.parametrize('reason', [{'kind': 'FALLTHROUGH'}, {'kind': 'ERROR', 'errorKind': 'MALFORMED_FLAG'}])
def test_flag_metadata_includes_override_affected_when_true(reason: dict, details_converter: ResolutionDetailsConverter):
detail = EvaluationDetail(True, None, {**reason, 'overrideAffected': True})
resolution_details = details_converter.to_resolution_details(detail)
assert resolution_details.flag_metadata == {'overrideAffected': True}


@pytest.mark.parametrize('reason', [{}, {'overrideAffected': False}, {'overrideAffected': None}, {'overrideAffected': 1}])
def test_flag_metadata_omits_override_affected_when_not_true(reason: dict, details_converter: ResolutionDetailsConverter):
detail = EvaluationDetail(True, 1, {'kind': 'FALLTHROUGH', **reason})
resolution_details = details_converter.to_resolution_details(detail)
assert resolution_details.flag_metadata == {'variationIndex': 1}


def test_flag_metadata_includes_the_rule_for_rule_matches(details_converter: ResolutionDetailsConverter):
detail = EvaluationDetail(True, 1, {'kind': 'RULE_MATCH', 'ruleIndex': 2, 'ruleId': 'the-rule-id'})
resolution_details = details_converter.to_resolution_details(detail)
Expand Down
Loading