feat(multivariate): report variant key on identities flag responses#7723
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7723 +/- ##
========================================
Coverage 98.52% 98.53%
========================================
Files 1445 1446 +1
Lines 55083 55371 +288
========================================
+ Hits 54273 54561 +288
Misses 810 810 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7139f01 to
888e420
Compare
888e420 to
25d3a5e
Compare
25d3a5e to
59d16c9
Compare
Add a `variant` field to each flag returned by /api/v1/identities/, so SDKs and experimentation can tell which multivariate variant an identity was exposed to. The value is the matched multivariate option's key, "control" when the identity falls through to the base value, or null for non-multivariate features. Scoped to the identities endpoint via a dedicated SDKIdentityFeatureStateSerializer subclass, leaving /api/v1/flags/ (which has no identity to evaluate against) untouched.
59d16c9 to
7653499
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the SDKIdentityFeatureStateSerializer to include a variant field in feature states evaluated for specific identities, falling back to a control variant if needed. It also adds corresponding integration and unit tests. The review feedback suggests using .get("identity") instead of direct dictionary access on self.context to avoid potential KeyError exceptions when the serializer is instantiated without an identity context, such as during OpenAPI schema generation.
Docker builds report
|
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
|
Visual Regression19 screenshots compared. See report for details. |
docs/if required so people know about the feature. (deferred — docs will land once SDKs surfacevariant.)Changes
Contributes to
Adds a
variantfield to each flag returned by/api/v1/identities/, so SDKs and experimentation can tell which multivariate variant an identity was exposed to:{ "feature": {...}, "enabled": true, "feature_state_value": "blue", "variant": "control" }The value is:
key, or"control"when the identity falls through to the base (control) value, ornullfor non-multivariate features.Implementation notes:
SDKIdentityFeatureStateSerializersubclass (features/serializers.py), wired intoIdentifyWithTraitsSerializer.flagsand the single-feature GET./api/v1/flags/shares the parent serializer and is left untouched — it has no identity to evaluate against (verified by a scoping test).FeatureState.get_multivariate_feature_state_value);"control"uses a newCONTROLconstant infeatures/constants.py.How did you test this code?
Automated tests, written TDD-first (Given/When/Then):
tests/integration/environments/identities/): parametrised over an identity hashing into variant 1, variant 2, and the control fall-through → asserts the correctvariantkey (and"control"); a standard feature reportsvariant: null; and/api/v1/flags/responses contain novariantfield (scoping proof).tests/unit/features/test_unit_features_serializers.py):get_variantreturnsnullwhen no identity is in serializer context.Verification run locally:
ruff check,ruff format --check, andmypy(strict, incl. tests): clean.Follow-ups (not in this PR)
sdk/openapi.yaml)