feat: include selected variant key in flag results#314
Draft
gagantrivedi wants to merge 1 commit into
Draft
Conversation
When a multivariate variant wins the percentage split, its key (a stable, human-readable identifier defined on the multivariate option) is now exposed as `variant` in the flag result, following OpenFeature's ResolutionDetails.variant naming. The field is omitted when no variant is selected or the selected variant has no key. Generated types are updated to match the evaluation schema changes in Flagsmith/flagsmith#7704.
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against b9b4d1f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
When a multivariate variant wins the percentage split, its
key— a stable, human-readable identifier defined on the multivariate option and delivered via the environment document — is now exposed asvariantin theFlagResult:{ "name": "checkout_button", "enabled": true, "value": "blue", "reason": "SPLIT; weight=30", "variant": "control" }flag_engine/context/types.py(generated):FeatureValuegainskey: NotRequired[str]flag_engine/result/types.py(generated):FlagResultgainsvariant: NotRequired[str]flag_engine/segments/evaluator.py:get_flag_result_from_context()carries the winning variant's key into the result; omitted when no variant is selected or the variant has no key (consistent with the schemas, and maps 1:1 to OpenFeature'sResolutionDetails.variant—None/undefinedat that layer)No change to selection logic, hashing, or variant ordering — purely an additive passthrough. This is a
feat:commit, so release-please will cut a minor (10.2.0).How did you test this code?
TDD — the new parametrised test in
tests/unit/segments/test_segments_evaluator.pycovers:variantpresent in the resultvariantomittedvariantomittedFull suite: 378 passed, including the shared
engine-test-datacorpus untouched — keyless documents evaluate identically, proving backwards compatibility.mypy(strict),black,flake8,isortall clean.The generated type changes were verified by running
datamodel-code-generator0.33.0 against the updated schemas and confirming the emitted field shapes match.