flagsmith
flagsmith copied to clipboard
Trying to edit a segment to put a 50% split AFTER some other conditions but after save it reverts to being the first condition
How are you running Flagsmith
- [ ] Self Hosted with Docker
- [ ] Self Hosted with Kubernetes
- [X] SaaS at flagsmith.com
- [ ] Some other way (add details in description below)
Describe the bug
This was a customer issue reported over chat.
@matthewelwell reported:
It seems as though, in production at least, the API is returning the nested rules in reverse order. I have tried to reproduce this in a unit test using the exact data that reproduces the issue in the production but I have so far not been able to (branch here: https://github.com/Flagsmith/flagsmith/tree/fix/show-segment-rules-in-the-correct-order). More testing in production needed to see if this is also an issue when evaluating segments or not.
Steps To Reproduce
Unclear
Expected behavior
Results come back in the correct order/
Screenshots
No response
This is affecting our production instance (SaaS) as well. We were attempting to target a segment via a trait condition and then do split % on that. When creating the segment the UI looks fine, but when hitting save it returns back with the split first. Let me know if you want any more info to help debug. This is a needed feature for us.
EDIT: A colleague used an existing segment and managed to get the ordering to work? 🤷 My example above was on a brand new segment.
cc @rolodato @kyle-ssg can we investigate pls!
Looking into this now, I'll write back ASAP with details.
I've confirmed this is a bug. To reproduce, create a segment like this:
The UI correctly creates the segment with this payload:
POST https://api.flagsmith.com/api/v1/projects/{project_id}/segments
{
"description": "",
"name": "debug_3600",
"project": "16945",
"rules": [
{
"conditions": [],
"rules": [
{
"conditions": [
{
"operator": "EQUAL",
"property": "trait_1",
"value": "1"
}
],
"rules": [],
"type": "ANY"
},
{
"conditions": [
{
"operator": "EQUAL",
"property": "trait_2",
"value": "2"
}
],
"rules": [],
"type": "ANY"
},
{
"conditions": [
{
"operator": "EQUAL",
"property": "trait_3",
"value": "3"
}
],
"rules": [],
"type": "ANY"
},
{
"conditions": [
{
"operator": "EQUAL",
"property": "trait_4",
"value": "4"
}
],
"rules": [],
"type": "ANY"
}
],
"type": "ALL"
}
]
}
When segments are listed from the API, the conditions are returned in inverse order (only showing the relevant segment here):
GET https://app.flagsmith.com/project/{project_id}/segments
{
"count": 10,
"next": null,
"previous": null,
"results": [
{
"id": 30488,
"rules": [
{
"id": 100032,
"type": "ALL",
"rules": [
{
"id": 100036,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428373,
"operator": "EQUAL",
"property": "trait_4",
"value": "4",
"description": null
}
]
},
{
"id": 100035,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428372,
"operator": "EQUAL",
"property": "trait_3",
"value": "3",
"description": null
}
]
},
{
"id": 100034,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428371,
"operator": "EQUAL",
"property": "trait_2",
"value": "2",
"description": null
}
]
},
{
"id": 100033,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428370,
"operator": "EQUAL",
"property": "trait_1",
"value": "1",
"description": null
}
]
}
],
"conditions": []
}
],
"deleted_at": null,
"uuid": "aa6f437f-0d3e-48d1-8b26-452ab31bd9a9",
"name": "debug_3600",
"description": "",
"project": 16945,
"feature": null
}
]
}
We get the same result when fetching only this segment:
GET https://api.flagsmith.com/api/v1/projects/{project_id}/segments/{segment_id}/
{
"id": 30488,
"rules": [
{
"id": 100032,
"type": "ALL",
"rules": [
{
"id": 100036,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428373,
"operator": "EQUAL",
"property": "trait_4",
"value": "4",
"description": null
}
]
},
{
"id": 100035,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428372,
"operator": "EQUAL",
"property": "trait_3",
"value": "3",
"description": null
}
]
},
{
"id": 100034,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428371,
"operator": "EQUAL",
"property": "trait_2",
"value": "2",
"description": null
}
]
},
{
"id": 100033,
"type": "ANY",
"rules": [],
"conditions": [
{
"id": 428370,
"operator": "EQUAL",
"property": "trait_1",
"value": "1",
"description": null
}
]
}
],
"conditions": []
}
],
"deleted_at": null,
"uuid": "aa6f437f-0d3e-48d1-8b26-452ab31bd9a9",
"name": "debug_3600",
"description": "",
"project": 16945,
"feature": null
}
A similar bug happens when editing segments. In the same example, if you add a new condition and then save:
The API returns the segment in a different order: