fix(multivariate): Handled missing default_percentage_allocation in option validation#6750
Open
adityapradhan10 wants to merge 15 commits intoFlagsmith:mainfrom
Open
Conversation
|
@adityapradhan10 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
for more information, see https://pre-commit.ci
…entage_allocation
for more information, see https://pre-commit.ci
api/tests/integration/features/multivariate/test_integration_multivariate.py
Show resolved
Hide resolved
khvn26
requested changes
Feb 24, 2026
Member
khvn26
left a comment
There was a problem hiding this comment.
The fix looks solid to me. Need to address test naming convention/typing.
api/tests/integration/features/multivariate/test_integration_multivariate.py
Outdated
Show resolved
Hide resolved
api/tests/integration/features/multivariate/test_integration_multivariate.py
Outdated
Show resolved
Hide resolved
api/tests/integration/features/multivariate/test_integration_multivariate.py
Outdated
Show resolved
Hide resolved
api/tests/integration/features/multivariate/test_integration_multivariate.py
Outdated
Show resolved
Hide resolved
…tion and added types
api/tests/integration/features/multivariate/test_integration_multivariate.py
Outdated
Show resolved
Hide resolved
api/tests/integration/features/multivariate/test_integration_multivariate.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
api/tests/integration/features/multivariate/test_integration_multivariate.py
Show resolved
Hide resolved
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.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #6615
Fixes a KeyError when creating or updating multivariate options via the API without specifying optional fields.
Root cause: The
validate()method inMultivariateFeatureOptionSerializeraccessedattrs["feature"]andattrs["default_percentage_allocation"]directly, causing crashes on partial updates or creates when these fields were omitted.Fixes a
KeyErrorwhen creating or updating multivariate options via the API when optional fields are omitted.Root cause:
MultivariateFeatureOptionSerializer.validate()usedattrs["feature"]andattrs["default_percentage_allocation"], which raises when those keys are missing on partial updates or when creating via nested routes without sending them.Fix:
feature: Resolved with fallbacks:attrs.get("feature"), then for updatesself.instance.feature, then for nested routes the feature from URLkwargs (feature_pk / project_pk). The serializer marks feature as not required viaextra_kwargsso POSTs without feature (e.g. when the feature is in the path) still reachvalidate().default_percentage_allocation: Resolved withattrs.get(..., instance_default_allocation), whereinstance_default_allocationis the instance value when present, or 100 for creates or legacy rows with NULL. The chosen value is written back intoattrs["default_percentage_allocation"]so validation and persistence stay in sync and legacy NULL is corrected on save.Note: No documentation changes required - this is a bug fix for the existing API behaviour, not a new feature.
How did you test this code?
test_create_mv_option__without_feature_in_payload__uses_feature_from_url– Create without feature in the body (feature from URL) → 201 and correct feature / allocation.test_create_mv_option__without_default_percentage_allocation__uses_default– Create without default_percentage_allocation → 201 and value 100.test_create_mv_option__without_default_percentage_allocation_with_existing_sibling_and_total_gt_100__returns_400– Create without allocation when a sibling has 50% → 400 and "Invalid percentage allocation".test_partial_update_mv_option__without_feature_and_allocation__uses_existing_values– PATCH without feature or default_percentage_allocation → 200 and existing values kept.test_partial_update_mv_option__handles_legacy_null_default_percentage_allocation– Serializer update with an instance that has default_percentage_allocation is None in memory → validates as 100 and persists 100 (legacy NULL handling).test_partial_update_default_percentage_allocation__sibling_total_gt_100__returns_400– PATCH that would push total allocation over 100% → 400 and "Invalid percentage allocation".