fix(v2): validate segment references when creating flags#4749
Merged
Conversation
When creating a flag resource via the v2 API with non-existent segment references, the flag was created but would lead to snapshot creation errors and inconsistent state. This fix adds validation during flag creation to ensure all referenced segments exist in both rules and rollouts before persisting the flag. - Added segment existence validation in PutResource for flags - Check segments referenced in both rules and rollouts - Added comprehensive test coverage for the validation logic - Tests verify rejection of invalid segments and acceptance of valid ones Fixes #4748 Signed-off-by: Mark Phelps <[email protected]>
|
Related Documentation Checked 3 published document(s). No updates required. You have 3 draft document(s). Publish docs to keep them always up-to-date |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v2 #4749 +/- ##
==========================================
+ Coverage 62.44% 62.67% +0.22%
==========================================
Files 132 132
Lines 15576 15594 +18
==========================================
+ Hits 9727 9773 +46
+ Misses 5165 5139 -26
+ Partials 684 682 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Documentation Updates Checked 3 published document(s). No updates required. You have 3 draft document(s). Publish docs to keep them always up-to-date |
ptejasvini
pushed a commit
to ptejasvini/flipt
that referenced
this pull request
Oct 3, 2025
When creating a flag resource via the v2 API with non-existent segment references, the flag was created but would lead to snapshot creation errors and inconsistent state. This fix adds validation during flag creation to ensure all referenced segments exist in both rules and rollouts before persisting the flag. - Added segment existence validation in PutResource for flags - Check segments referenced in both rules and rollouts - Added comprehensive test coverage for the validation logic - Tests verify rejection of invalid segments and acceptance of valid ones Fixes flipt-io#4748 Signed-off-by: Mark Phelps <[email protected]> Signed-off-by: tejasvini1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #4748 where creating a flag resource with non-existent segment references via the v2 API would result in an inconsistent state. The flag would be created successfully but would cause snapshot creation errors and UI issues.
Changes
internal/storage/environments/fs/flipt/flags.go: Added validation inPutResourcemethod to check that all referenced segments exist before saving a flaginternal/storage/environments/fs/flipt/flags_test.go: Comprehensive test coverage for the new validation logic including:Problem Details
Previously, when creating a flag like this with a non-existent segment "buzz":
{ "key": "flag1", "rollouts": [{ "type": "SEGMENT_ROLLOUT_TYPE", "segment": { "segments": ["buzz"] } }] }The flag would be created but would cause:
flag default/flag1 rule 1 references unknown segment "buzz"Solution
The fix validates all segment references during flag creation/update:
This ensures data consistency and prevents the creation of invalid flag configurations.
Fixes #4748