Skip to content

fix(Multivariate): creating an option without default_percentage_allocation returns 500 - #8202

Open
bardock-2393 wants to merge 1 commit into
Flagsmith:mainfrom
bardock-2393:fix/mv-option-missing-percentage-allocation
Open

fix(Multivariate): creating an option without default_percentage_allocation returns 500#8202
bardock-2393 wants to merge 1 commit into
Flagsmith:mainfrom
bardock-2393:fix/mv-option-missing-percentage-allocation

Conversation

@bardock-2393

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #6615

MultivariateFeatureOptionSerializer.validate() reads attrs["default_percentage_allocation"] directly. The model field has default=100, which makes DRF mark the serializer field required=False, but DRF does not carry a model field's default into validated_data — it only omits the key entirely from attrs if the request doesn't supply it. So POSTing to create a multivariate option without default_percentage_allocation in the payload raised an unhandled KeyError (500) instead of falling back to the model's own default of 100.

Fixed by declaring the field explicitly on the serializer with default=100 (carrying forward the existing min_value/max_value validators), so DRF always populates validated_data with it.

How did you test this code?

Added test_create_mv_option__no_default_percentage_allocation__defaults_to_100, following the existing integration test conventions in test_integration_multivariate.py. Confirmed it reproduces the exact reported KeyError when temporarily reverting the fix, and passes with the fix applied. Ran the full multivariate test suite (65 tests, unit + integration) — all green. Ran make lint and make typecheck — both clean.

…cation returns 500

MultivariateFeatureOptionSerializer.validate() read
attrs["default_percentage_allocation"] directly. The model field has
default=100, which makes DRF mark the serializer field optional, but
DRF does not carry the model's default into validated_data — so
omitting the key from the request raised an unhandled KeyError instead
of falling back to 100.
@bardock-2393
bardock-2393 requested a review from a team as a code owner August 1, 2026 18:20
@bardock-2393
bardock-2393 requested review from emyller and removed request for a team August 1, 2026 18:20
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@bardock-2393 is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9316ef6f-d556-4995-b958-934b00937ac5

📥 Commits

Reviewing files that changed from the base of the PR and between fc33002 and c63e3a1.

📒 Files selected for processing (2)
  • api/features/multivariate/serializers.py
  • api/tests/integration/features/multivariate/test_integration_multivariate.py

📝 Walkthrough

Walkthrough

The multivariate option serializer now defines default_percentage_allocation as an optional float with a default of 100 and bounds from 0 to 100. An integration test verifies that option creation succeeds when the field is omitted and that the stored allocation is 100%.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the api Issue related to the REST API label Aug 1, 2026
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.57%. Comparing base (fc33002) to head (c63e3a1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8202      +/-   ##
==========================================
- Coverage   98.71%   98.57%   -0.15%     
==========================================
  Files        1531     1531              
  Lines       61263    61265       +2     
==========================================
- Hits        60475    60390      -85     
- Misses        788      875      +87     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Insufficient validation in /api/v1/projects/{project_pk}/features/{feature_pk}/mv-options/

1 participant