Bug Description
When a segment is created via the Admin API with multiple top-level rules (i.e., the rules array at the segment level has 2+ entries), the dashboard UI only renders the first top-level rule. Additional rules are completely invisible in the visual editor there is no scroll and no indicator.
The API accepts and returns all rules correctly. The data is stored and the flag engine evaluates all rules. But the UI silently hides everything after rules[0].
Editing the segment in the dashboard would silently drop the hidden rules.
Steps to Reproduce
- Create a segment via Admin API with two top-level rule groups:
POST /api/v1/projects/{PROJECT_ID}/segments/
With two entries in the top level rules array, each with type ALL and containing sub-rules scoped to different environments via $.environment.name.
- Verify the API response contains both top level rules
- Open the segment in the Flagsmith dashboard
Expected Behavior
The UI should display both top level rule groups, or at minimum indicate that additional rules exist.
Actual Behavior
Only the first top level rule group is rendered. The second is completely missing from the editor.
Root Cause
The frontend hard codes rules[0] throughout CreateSegment.tsx:
- addRule() (line ~214): appends to
rules[0].rules
- updateRule() (line ~224): modifies
rules[0].rules[elementNumber]
- Rendering (line ~338): maps over
rules[0].rules only
- Validation: checks only
rules[0].rules
The UI assumes a single top level ALL wrapper rule. The API and backend have no constraint. The serializer uses many=True and the DB model supports multiple top level rules via FK.
Impact
- Users creating segments via API with multiple top-level rules see incomplete data in the UI
- Editing such a segment in the dashboard silently drops hidden rules (data loss)
- Use case: customers migrating from other vendors who want one segment with per-environment targeting rules
Suggested Fix
Either:
- Frontend: Update the UI to iterate over all top-level rules instead of only
rules[0]
- Backend: Add API validation to reject/warn when multiple top-level rules are submitted
- Both: Render them properly and decide if this is an intended feature
At minimum, the UI should warn when hidden rules exist to prevent silent data loss on edit.
Bug Description
When a segment is created via the Admin API with multiple top-level rules (i.e., the
rulesarray at the segment level has 2+ entries), the dashboard UI only renders the first top-level rule. Additional rules are completely invisible in the visual editor there is no scroll and no indicator.The API accepts and returns all rules correctly. The data is stored and the flag engine evaluates all rules. But the UI silently hides everything after
rules[0].Editing the segment in the dashboard would silently drop the hidden rules.
Steps to Reproduce
POST /api/v1/projects/{PROJECT_ID}/segments/
With two entries in the top level rules array, each with type ALL and containing sub-rules scoped to different environments via $.environment.name.
Expected Behavior
The UI should display both top level rule groups, or at minimum indicate that additional rules exist.
Actual Behavior
Only the first top level rule group is rendered. The second is completely missing from the editor.
Root Cause
The frontend hard codes
rules[0]throughoutCreateSegment.tsx:rules[0].rulesrules[0].rules[elementNumber]rules[0].rulesonlyrules[0].rulesThe UI assumes a single top level ALL wrapper rule. The API and backend have no constraint. The serializer uses
many=Trueand the DB model supports multiple top level rules via FK.Impact
Suggested Fix
Either:
rules[0]At minimum, the UI should warn when hidden rules exist to prevent silent data loss on edit.