Skip to content

API accepts multivariate percentage splits over 100% #7369

@emyller

Description

@emyller

How are you running Flagsmith

  • SaaS at flagsmith.com

Describe the bug

When a feature state ends up with MultivariateFeatureStateValue.percentage_allocation rows summing to more than 100%, process_environment_update fails when map_feature_state_to_engine raises a Pydantic ValidationError from FeatureStateModel. While that state persists, the environment document on DynamoDB is never rewritten, so the Edge API keeps serving the previous value of every flag in that environment regardless of what the dashboard shows.

Acceptance criteria

  • It is not possible to leave a feature state's MultivariateFeatureStateValue.percentage_allocation rows summing to more than 100% in the database, by any means.

How to reproduce

There is one observed case in production, with unclear reproduction steps. I was able to reproduce it in the API via mv-options:

  1. Pick a feature whose env-default feature state already has multivariate percentage allocations summing to 100%.
  2. POST /api/v1/projects/<project_id>/features/<feature_id>/mv-options/ with a body whose default_percentage_allocation is greater than zero.
  3. GET /api/v1/environments/<environment_api_key>/featurestates/?feature=<feature_id> and observe the env-default feature state's multivariate_feature_state_values now summing to more than 100%.
Image

In the above screenshot, the dashboard displays the faulty MV setup, with an error message, when it already exists.

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