Skip to content

fix: Send a null property so percentage-split segments can be created - #122

Open
0xvikram wants to merge 1 commit into
Flagsmith:mainfrom
0xvikram:fix/percentage-split-property
Open

0xvikram wants to merge 1 commit into
Flagsmith:mainfrom
0xvikram:fix/percentage-split-property

Conversation

@0xvikram

Copy link
Copy Markdown

flagsmith segment create --rules can't create a percentage-split segment, the usual building block of a gradual rollout.

What happens

flagsmith segment create rollout --rules '{"type":"ALL","rules":[{"type":"ANY","conditions":[{"operator":"PERCENTAGE_SPLIT","value":"25"}]}]}'
Error: POST https://api.flagsmith.com/api/v1/projects/<id>/segments/ returned 500 Internal Server Error

SegmentCondition.Property is omitempty, so a condition with no property is sent without the key. Sending the same body to the Admin API directly:

  • "property": null → 201 Created
  • "property": "" → 400
  • key omitted (what the CLI sends) → 500

segment update --rules goes through the same path.

Fix

SegmentCondition now always sends property, as null when it is empty, which is how the API stores it. Conditions that have a property are unchanged.

Verified

  • New test TestSegmentCreate/sends a null property for a percentage split checks the wire body. It fails without the fix.
  • go vet ./... and go test -race ./... pass.
  • A binary built from this branch created a 25% split segment on Flagsmith Cloud, and Flagsmith's segment editor showed it as "% Split 25".

Found while building a staged-rollout agent skill on the CLI (https://github.com/0xvikram/ship-safely).

This contribution was prepared with AI coding assistance.

segment create/update dropped an empty "property" from conditions. The Admin API
answers a PERCENTAGE_SPLIT condition without that key with a 500, so a percentage
rollout segment could not be created from the CLI. Conditions now always send
"property", as null when empty, which is how the API stores it.
@0xvikram
0xvikram requested a review from a team as a code owner November 27, 2026 07:43
@0xvikram
0xvikram requested review from khvn26 and a balanced review from Copilot and removed request for a team November 27, 2026 07:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants