Skip to content

fix: feature_segment missing in versioning#7618

Merged
matthewelwell merged 1 commit into
Flagsmith:mainfrom
SahilJat:fix/missing-feature-segment
May 29, 2026
Merged

fix: feature_segment missing in versioning#7618
matthewelwell merged 1 commit into
Flagsmith:mainfrom
SahilJat:fix/missing-feature-segment

Conversation

@SahilJat
Copy link
Copy Markdown
Contributor

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 #7587

Fixes a 500 error that occurs when feature_segment is completely missing from feature_states_to_create.

Swapped fs["feature_segment"] for fs.get("feature_segment") in segment_ids_to_create_overrides to safely handle missing keys and prevent KeyError crashes. The existing validation now correctly catches this and returns a 400.

How did you test this code?

Added a test case verifying that a payload entirely missing the feature_segment key returns a 400 with the proper error message instead of a 500.

@SahilJat SahilJat requested a review from a team as a code owner May 28, 2026 08:34
@SahilJat SahilJat requested review from emyller and removed request for a team May 28, 2026 08:34
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@SahilJat 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 May 28, 2026
@SahilJat SahilJat changed the title fix:feature_segment missing in versioning fix: feature_segment missing in versioning May 28, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a potential KeyError (which resulted in a 500 Internal Server Error) when the feature_segment key is entirely omitted from the feature_states_to_create payload. By using .get("feature_segment") instead of direct key access, the code now safely handles missing keys. A unit test has also been added to verify that a 400 Bad Request is returned instead of a 500 error. I have no further feedback to provide as the changes are correct and well-tested.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.36%. Comparing base (482f0ff) to head (3bde472).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7618      +/-   ##
==========================================
- Coverage   98.51%   98.36%   -0.16%     
==========================================
  Files        1439     1439              
  Lines       54690    54577     -113     
==========================================
- Hits        53880    53685     -195     
- Misses        810      892      +82     

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

@matthewelwell
Copy link
Copy Markdown
Contributor

Thanks @SahilJat !

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 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 29, 2026 3:20pm
flagsmith-frontend-preview Ignored Ignored Preview May 29, 2026 3:20pm
flagsmith-frontend-staging Ignored Ignored Preview May 29, 2026 3:20pm

Request Review

@matthewelwell matthewelwell merged commit f5584c9 into Flagsmith:main May 29, 2026
26 checks passed
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.

Handle missing feature_segment on version create

2 participants