fix(Multivariate): creating an option without default_percentage_allocation returns 500 - #8202
Conversation
…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 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe multivariate option serializer now defines Estimated code review effort: 2 (Simple) | ~10 minutes ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #6615
MultivariateFeatureOptionSerializer.validate()readsattrs["default_percentage_allocation"]directly. The model field hasdefault=100, which makes DRF mark the serializer fieldrequired=False, but DRF does not carry a model field's default intovalidated_data— it only omits the key entirely fromattrsif the request doesn't supply it. So POSTing to create a multivariate option withoutdefault_percentage_allocationin the payload raised an unhandledKeyError(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 existingmin_value/max_valuevalidators), so DRF always populatesvalidated_datawith 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 intest_integration_multivariate.py. Confirmed it reproduces the exact reportedKeyErrorwhen temporarily reverting the fix, and passes with the fix applied. Ran the full multivariate test suite (65 tests, unit + integration) — all green. Ranmake lintandmake typecheck— both clean.