Skip to content

fix(versioning): update segment override in place when patch omits feature_segment.id - #8515

Open
Tyagiquamar wants to merge 1 commit into
Flagsmith:mainfrom
Tyagiquamar:fix/versioned-override-patch-without-id
Open

Tyagiquamar wants to merge 1 commit into
Flagsmith:mainfrom
Tyagiquamar:fix/versioned-override-patch-without-id

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Changes

Closes #8395

PATCH .../featurestates/{id}/ with a feature_segment payload omitting id now updates the existing FeatureSegment in place. EnvironmentFeatureVersionFeatureStatesViewSet.get_serializer defaults feature_segment.id from the instance on update/partial_update, mirroring EnvironmentFeatureVersionCreateSerializer._update_feature_state. Previously drf-writable-nested saw no pk, inserted a duplicate FeatureSegment, and the request 500d on the unique constraint.

How did you test this code?

  • New integration test test_versioned_featurestate__patch_without_feature_segment_id__updates_in_place reproduces PATCHing a versioned segment override without feature_segment.id returns a 500 #8395 (PATCH without id expects 200 and unchanged feature_segment id).
  • Targeted collection passes: 6/6 tests collected including the new one.
  • ruff check and ruff format --check on both touched files: pass.
  • Note: the DB-backed integration run could not execute on this host (no Postgres/Docker daemon; OperationalError on localhost:5432), so green run is left to CI. A DB-free logic simulation of the id-defaulting (missing id injected, present id untouched, no nested payload untouched, null segment untouched, list unaffected) passes 5/5.
  • Full suite not run (too heavy); change is scoped to api/features/versioning.

@Tyagiquamar
Tyagiquamar requested a review from a team as a code owner September 13, 2026 18:05
@Tyagiquamar
Tyagiquamar requested review from emyller and removed request for a team September 13, 2026 18:05
@vercel

vercel Bot commented Sep 13, 2026

Copy link
Copy Markdown

@Tyagiquamar is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Sep 13, 2026
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 63c3eaa9-1411-4132-af2a-81123721382d

📥 Commits

Reviewing files that changed from the base of the PR and between a82c3d6 and 57e6372.

📒 Files selected for processing (2)
  • api/features/versioning/views.py
  • api/tests/integration/features/versioning/test_integration_v2_versioning.py

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

EnvironmentFeatureVersionFeatureStatesViewSet.get_serializer now adds the existing feature_segment_id to update payloads when feature_segment.id is absent. The change applies to update and partial_update actions. An integration test verifies that a PATCH request without the nested id returns HTTP 200 and preserves the original feature segment id.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 57e63

The versioned segment override PATCH behavior is covered and no actionable current-head risk remains.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PATCHing a versioned segment override without feature_segment.id returns a 500

1 participant