Skip to content

Partially updating a multivariate option returns 500 #8901

Closed as duplicate

Description

@himanshu007-creator

How are you running Flagsmith

  • Self Hosted with Docker (docker.flagsmith.com/flagsmith/flagsmith:latest = 2.290.0, upstream docker-compose.yml)
  • Self Hosted with Kubernetes
  • SaaS at flagsmith.com
  • Some other way

Describe the bug

PATCH /api/v1/projects/{project_pk}/features/{feature_pk}/mv-options/{id}/ returns 500 Internal Server Error for any partial update of a multivariate option, including the common case of setting a variant key on an existing option.

MultivariateFeatureOptionSerializer.validate() reads attrs["feature"] and attrs["default_percentage_allocation"] unconditionally. DRF omits fields that are not in the request body on partial updates, so the lookup raises KeyError. PUT with a full body works, which is why the dashboard never hits this; API, MCP (update_feature_multivariate_option) and script users do.

Traceback (API container logs):

Internal Server Error: /api/v1/projects/1/features/1/mv-options/1/
  ...
  File ".../rest_framework/serializers.py", line 225, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  ...
  File "/build/api/features/multivariate/serializers.py", line 85, in validate
    feature = attrs["feature"]
KeyError: 'feature'

Steps To Reproduce

  1. Run Flagsmith 2.290.0 (upstream docker-compose.yml), create a project and a multivariate feature with one option.
  2. curl -X PATCH http://localhost:8000/api/v1/projects/1/features/1/mv-options/1/ -H 'Authorization: Token <key>' -H 'content-type: application/json' -d '{"key":"variant_a"}'
  3. Observe HTTP 500 and the KeyError: 'feature' traceback above. Including "feature": 1 in the body still fails, this time on default_percentage_allocation.

Expected behavior

The option is updated and 200 is returned, with the same allocation and key-uniqueness validation that PUT applies.

Screenshots

Not applicable (API only).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions