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

Đang mở Phù hợp với người mới
#9,152 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu tại api/segments/serializers.py, ở SegmentSerializer._get_clean_rules_and_conditions, sau đó kiểm tra việc xác thực điều kiện và xử lý chia theo tỷ lệ phần trăm trong flag_engine/segments/evaluator.py. Tái hiện yêu cầu Admin API trong issue và xem các bài kiểm thử serializer phân đoạn hiện có. Công việc hoàn tất khi có thể tạo một phép chia theo tỷ lệ phần trăm không có property và phép chia đó vẫn dùng khóa định danh, đồng thời việc xác thực các điều kiện khác vẫn được kiểm thử.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
9.9k
Fork
658
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
171

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Flagsmith/flagsmith

Tất cả issue của Flagsmith/flagsmith

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.