Skip to content

fix: Feature.type field is unbounded#6888

Merged
khvn26 merged 4 commits intomainfrom
fix/feature-type-field-unbounded
Mar 9, 2026
Merged

fix: Feature.type field is unbounded#6888
khvn26 merged 4 commits intomainfrom
fix/feature-type-field-unbounded

Conversation

@khvn26
Copy link
Member

@khvn26 khvn26 commented Mar 9, 2026

  • 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 #6886

In this PR, we constrain the Feature.type field to only accept valid choices (STANDARD, MULTIVARIATE), fixing a bug where arbitrary strings (e.g. "boolean") could be written and then break Pydantic validation in EnvironmentCompressed.

  • Re-export FeatureType from flagsmith_schemas.types (single source of truth) and derive FEATURE_TYPE_CHOICES from it.
  • Add choices=FEATURE_TYPE_CHOICES to the Feature.type model field.
  • Make type read-only in CreateFeatureSerializer — it is already derived automatically by MultivariateFeatureOption lifecycle hooks.
  • Add a data migration to fix existing invalid values: features with multivariate options get MULTIVARIATE, all others get STANDARD.

How did you test this code?

  • Migration test: creates features with invalid type values ("boolean", "flag"), applies migration, asserts they are corrected.
  • View test: verifies that type is ignored when provided in a create request and defaults to STANDARD.

@khvn26 khvn26 requested a review from a team as a code owner March 9, 2026 16:23
@khvn26 khvn26 requested review from gagantrivedi and removed request for a team March 9, 2026 16:23
@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 9, 2026 4:52pm
flagsmith-frontend-preview Ignored Ignored Preview Mar 9, 2026 4:52pm
flagsmith-frontend-staging Ignored Ignored Preview Mar 9, 2026 4:52pm

Request Review

@khvn26 khvn26 changed the title fix: constrain Feature.type field to valid choices fix: Feature.type field is unbounded Mar 9, 2026
@github-actions github-actions bot added the api Issue related to the REST API label Mar 9, 2026
@github-actions github-actions bot added the fix label Mar 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6888 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6888 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-6888 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6888 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6888 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-6888 Finished ✅ Results

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  46.3 seconds
commit  d23d3ab
info  🔄 Run: #15175 (attempt 1)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  54.2 seconds
commit  d23d3ab
info  🔄 Run: #15175 (attempt 1)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 2 seconds
commit  d23d3ab
info  🔄 Run: #15175 (attempt 1)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 1 second
commit  d23d3ab
info  🔄 Run: #15175 (attempt 1)

@github-actions github-actions bot added fix and removed fix labels Mar 9, 2026
emyller
emyller previously approved these changes Mar 9, 2026
Copy link
Contributor

@emyller emyller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢it

@khvn26 khvn26 requested a review from a team as a code owner March 9, 2026 16:52
@github-actions github-actions bot added fix and removed fix labels Mar 9, 2026
@khvn26 khvn26 merged commit 48de147 into main Mar 9, 2026
32 checks passed
@khvn26 khvn26 deleted the fix/feature-type-field-unbounded branch March 9, 2026 17:01
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.34%. Comparing base (c5953c2) to head (d23d3ab).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6888   +/-   ##
=======================================
  Coverage   98.33%   98.34%           
=======================================
  Files        1334     1335    +1     
  Lines       49661    49707   +46     
=======================================
+ Hits        48836    48882   +46     
  Misses        825      825           

☔ View full report in Codecov by Sentry.
📢 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 fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature.type field is unbounded

4 participants