Creating a segment with a PERCENTAGE_SPLIT condition and no `property` returns 500 (KeyError: 'property')

未关闭 适合新手
#9,152 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

从 api/segments/serializers.py 中的 SegmentSerializer._get_clean_rules_and_conditions 开始,然后检查 flag_engine/segments/evaluator.py 中的条件验证和百分比拆分处理。重现 issue 中的 Admin API 请求,并检查现有的分段序列化器测试。当不带 property 也能创建百分比拆分,且仍使用身份键,同时其他条件的验证仍有测试覆盖时,即为完成。

由索引模型根据 Issue 内容生成。

描述

How are you running Flagsmith
  • Self Hosted with Docker
  • Self Hosted with Kubernetes
  • SaaS at flagsmith.com
  • Some other way (add details in description below)
Describe the bug

Creating a segment through the Admin API with a PERCENTAGE_SPLIT condition and no property fails with a 500.

The engine supports a split with no property: it hashes the identity key. Its own comment says, "Currently, the only supported condition with a blank property is percentage split" (flag_engine/segments/evaluator.py). But SegmentSerializer._get_clean_rules_and_conditions reads condition["property"] directly (api/segments/serializers.py, line 325 on main), which raises KeyError: 'property'.

Sending "property": "" or "property": null instead is rejected with a 400 ("property": ["This field may not be blank."]). So the API can't create a plain percentage split. The new CLI's flagsmith segment create --rules … gets the same 500.

Seen on Flagsmith 2.295.2 (Docker). The same code is on main as of 28 Nov 2026.

Steps To Reproduce
curl -X POST "$FLAGSMITH/api/v1/projects/$PROJECT/segments/" \
  -H "Authorization: Api-Key $ADMIN_KEY" -H "Content-Type: application/json" \
  -d '{"name":"Half of users","project":'"$PROJECT"',"rules":[{"type":"ALL","rules":[{"type":"ANY","rules":[],"conditions":[{"operator":"PERCENTAGE_SPLIT","value":"50"}]}],"conditions":[]}]}'

The response is HTTP 500, and the API log shows:

File "/app/segments/serializers.py", line 325, in _get_clean_rules_and_conditions
    "property": condition["property"],
KeyError: 'property'

With "property": "" or null instead, the response is HTTP 400: This field may not be blank.

Expected behavior

The segment is created as a percentage split over the identity key, which the engine already supports. Perhaps condition.get("property") in _get_clean_rules_and_conditions, with a blank property allowed for PERCENTAGE_SPLIT during validation.

Workaround: "property": "$.identity.key" creates a split that the engine hashes the same way.

Screenshots

n/a

Found while building flagsmith-toolbar, a developer toolbar for the Flagsmith JS SDK.

主要语言
Python
星标
9.9k
派生
658
平均合并
1 天 15 小时
30 天内合并 PR
171

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Flagsmith/flagsmith 的其他 Issue

查看 Flagsmith/flagsmith 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。