fix(api): block multivariate option changes during live experiments
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
Contributes to #8766
The API now rejects multivariate option changes on a feature that is in a running experiment:
MultivariateFeatureOptionViewSetcreate, update and destroy return 400 while the feature has a running experiment in any environment. Multivariate options belong to the feature, so one experiment locks them everywhere.- Feature create/update: the nested
multivariate_optionsare rejected only when the submitted options differ from the stored ones. The frontend resubmits the whole feature on save, so other fields (description, tags, etc.) still save on a frozen feature. - New helper
has_live_experimentinexperimentation/feature_state_metadata.py.
Frontend: the create-feature modal already disables the add, edit and remove variant controls when the feature is frozen (useFeatureExperimentFreeze). That check only looks at experiments running in the current environment. Blocking variant edits from the UI for a feature running in another environment needs a project-level experiments query, which is not part of this PR. The API rejects those edits regardless.
How did you test this code?
Backend unit tests:
cd api
pytest tests/unit/features/multivariate/test_unit_multivariate_live_experiment.py
pytest tests/unit/features/ -k "multivariate or mv or feature_serializer or create_feature or update_feature"
The new test module covers create, update and delete of MV options during a live experiment (400), the same create still working without one, and feature PATCH with changed options (400) versus unchanged options plus a metadata change (200). The existing multivariate and feature suites pass.