Skip to content

fix(versioning): reject legacy feature-state writes on v2 environments#7488

Merged
gagantrivedi merged 8 commits into
mainfrom
worktree-block-v2-fs-direct-put
May 13, 2026
Merged

fix(versioning): reject legacy feature-state writes on v2 environments#7488
gagantrivedi merged 8 commits into
mainfrom
worktree-block-v2-fs-direct-put

Conversation

@gagantrivedi
Copy link
Copy Markdown
Member

@gagantrivedi gagantrivedi commented May 12, 2026

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

Closes #7487

The non-versioning feature-state endpoints mutated the live FeatureState row in place on v2-versioned environments — bypassing the version graph (no new EnvironmentFeatureVersion, no audit row, no NEW_VERSION_PUBLISHED webhook) and silently losing the change on rollback.

This PR rejects POST/PUT/PATCH/DELETE against those endpoints with HTTP 400 on v2 environments and points callers at the versioning endpoint. Identity overrides remain allowed (they are not part of the version graph in v2).

Blocked routes (on v2 envs unless identity-scoped):

  • POST/PUT/PATCH/DELETE /api/v1/environments/{api_key}/featurestates/[{id}/]
  • POST/PUT/PATCH /api/v1/features/featurestates/[{id}/]

How did you test this code?

8 new unit tests in api/tests/unit/features/test_unit_features_views.py cover:

  • POST/PUT on both endpoints → 400 on v2
  • DELETE on the nested endpoint → 400 on v2 (row still exists)
  • Identity-scoped writes → still 200/201/204
  • The response detail mentions v2 feature versioning

Each blocking test is parametrised over admin_client and admin_master_api_key_client. mypy clean on the touched files.

Direct writes through the legacy feature-state CRUD endpoints mutated
the live FeatureState row in place on v2-versioned environments,
bypassing the version graph: no new EnvironmentFeatureVersion, no audit
row, no NEW_VERSION_PUBLISHED webhook, and the change was lost on
rollback to a prior version.

Reject these calls with 400 and point callers at the versioning
endpoint. Identity overrides stay allowed since they are not part of
the version graph.

Affected endpoints:
- POST/PUT/PATCH /api/v1/environments/{api_key}/featurestates/[{id}/]
- POST/PUT/PATCH /api/v1/features/featurestates/[{id}/]
@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 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 May 12, 2026 8:38am
flagsmith-frontend-preview Ignored Ignored Preview May 12, 2026 8:38am
flagsmith-frontend-staging Ignored Ignored Preview May 12, 2026 8:38am

Request Review

@github-actions github-actions Bot added api Issue related to the REST API fix labels May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.44%. Comparing base (b870482) to head (c595dd7).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7488    +/-   ##
========================================
  Coverage   98.44%   98.44%            
========================================
  Files        1398     1399     +1     
  Lines       52646    52764   +118     
========================================
+ Hits        51826    51944   +118     
  Misses        820      820            

☔ 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.

DELETE on the nested feature-state endpoint had the same version-graph
bypass as POST/PUT/PATCH: removing the live FS for an env or segment
override silently mutated the live EnvironmentFeatureVersion's row set.
Reject these calls with 400 too; identity-override deletes stay
allowed.
@github-actions github-actions Bot added fix and removed fix labels May 12, 2026
Co-locate the guard with update_flag() and the other v2-versioning
policy in features/versioning/versioning_service.py, and move the
exception alongside the other versioning errors. Rename the helpers to
require_direct_state_write/_for_state to signal that they raise.
Trim the exception message to a static one-liner.
@github-actions github-actions Bot added fix and removed fix labels May 12, 2026
pre-commit-ci Bot and others added 2 commits May 12, 2026 08:09
Drop the orienting comment from require_direct_state_write; the
function name and exception class carry the meaning. Add the
"v2 feature versioning" detail assertion to the three blocking tests
that were missing it for consistency.
@github-actions github-actions Bot added fix and removed fix labels May 12, 2026
@github-actions github-actions Bot added fix and removed fix labels May 12, 2026
The guard was too aggressive and rejected supported v2 flows where the
caller participates in the version graph explicitly. Two refinements:

- POST on the simple endpoint with environment_feature_version in the
  body is the supported way to create a segment override on a draft
  EFV. Skip the guard in that case.
- PUT/PATCH/DELETE against a FeatureState attached to an unpublished
  (draft) EnvironmentFeatureVersion is modifying a draft, not
  bypassing the version graph. Skip the guard in that case too.

Unblocks test_4eyes_workflow_with_v2_versioning. Adds two unit tests
covering both new allow paths.
@github-actions github-actions Bot added fix and removed fix labels May 12, 2026
@gagantrivedi gagantrivedi marked this pull request as ready for review May 12, 2026 08:47
@gagantrivedi gagantrivedi requested a review from a team as a code owner May 12, 2026 08:47
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for a team May 12, 2026 08:47
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

Docker builds report

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 12, 2026

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.6 seconds
commit  c595dd7
info  🔄 Run: #16692 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.7 seconds
commit  c595dd7
info  🔄 Run: #16692 (attempt 1)

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

passed  18 passed

Details

stats  18 tests across 14 suites
duration  1 minute, 8 seconds
commit  c595dd7
info  🔄 Run: #16692 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  33.1 seconds
commit  c595dd7
info  🔄 Run: #16692 (attempt 1)

@github-actions
Copy link
Copy Markdown
Contributor

Visual Regression

16 screenshots compared. See report for details.
View full report

Copy link
Copy Markdown
Contributor

@Zaimwa9 Zaimwa9 left a comment

Choose a reason for hiding this comment

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

1 nit otherwise lgtm

Comment thread api/features/versioning/exceptions.py
@gagantrivedi gagantrivedi merged commit 131f284 into main May 13, 2026
50 checks passed
@gagantrivedi gagantrivedi deleted the worktree-block-v2-fs-direct-put branch May 13, 2026 09:23
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.

Legacy /featurestates/ endpoints silently bypass the version graph on v2 environments

2 participants