feat(multivariate): thread variant key into the environment document#7699
Draft
gagantrivedi wants to merge 1 commit into
Draft
feat(multivariate): thread variant key into the environment document#7699gagantrivedi wants to merge 1 commit into
gagantrivedi wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
21137cc to
3fb6448
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/multivariate-option-key #7699 +/- ##
=============================================================
Coverage 98.52% 98.52%
=============================================================
Files 1445 1445
Lines 55021 55043 +22
=============================================================
+ Hits 54211 54233 +22
Misses 810 810 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add `key` to the engine `MultivariateFeatureOptionModel` and map it through in `map_mv_option_to_engine`, so the per-variant key flows into both the SDK local-evaluation document and the DynamoDB/edge document. The field is optional (defaults to None), mirroring the existing `id` field on the same model. Adding it is backward- and forward-compatible: consumers parse these documents with pydantic's default `extra='ignore'`, so a lagging Edge API reading a newer document silently ignores the unknown field, and new code reading an older document defaults `key` to None. Two regression tests lock in this round-trip guarantee.
3fb6448 to
768a723
Compare
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.
docs/if required so people know about the feature. (deferred — the key isn't surfaced to SDK consumers yet; docs land with the SDK/experimentation slices.)Changes
Contributes to
Threads the per-variant
key(added toMultivariateFeatureOptionin #7698) into the environment document so it's available to anything that reads that document.util/engine_models/features/models.py): addkey: Optional[str] = NonetoMultivariateFeatureOptionModel— same shape as the existingidfield.util/mappers/engine.py):map_mv_option_to_enginenow passeskey=mv_option.key. Both the SDK local-eval document (map_environment_to_sdk_document) and the DynamoDB/edge documentmodel_dump()the wholeEnvironmentModel, so the field propagates to both with no per-mapper change.Runtime variant selection (
_get_multivariate_value) is unchanged — it still returns the value. Surfacing the key in SDK/identify responses is a later slice.Backward/forward compatibility (DynamoDB + Edge API)
Adding this field is safe in both directions, verified rather than assumed:
extra='forbid'→ pydantic 2.x defaults toextra='ignore'.flagsmith-flag-enginepackage is entirelyTypedDict→ no runtime validation, unknown keys are inert.edge_api/identities/models.py,util/mappers/dynamodb.py); all tolerate extra fields.keydefaults toNone. New doc → lagging/old code (e.g. Edge API mid-deploy): unknown field ignored, no error.How did you test this code?
Automated, TDD-first (Given/When/Then):
test_map_mv_option_to_engine__option_with_key__includes_key— key propagates into the engine model.test_map_feature_state_to_engine__mv_option_with_key__key_in_serialised_document— key appears in the serialised document (model_dump), i.e. what's written to Dynamo / sent to SDKs.test_multivariate_feature_option_model__document_without_key__defaults_to_none— an older document (nokey) parses withkeydefaulting toNone.Existing edge_api integration tests assert the exact identity document written to DynamoDB; their snapshots (the shared
identity_documentfixture + one inline expected) were updated to include the newkeyfield.Verification run locally:
edge_api,environments,util, feature serializers, import/export): passing.ruff check,ruff format,mypy(strict): clean.