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

Offen Anfängerfreundlich
#9,152 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
api

Rechercherichtung

Beginne in api/segments/serializers.py bei SegmentSerializer._get_clean_rules_and_conditions und prüfe dann die Validierung der Bedingungen und die Behandlung der prozentualen Aufteilung in flag_engine/segments/evaluator.py. Reproduziere die Admin API-Anfrage aus dem Issue und prüfe die vorhandenen Tests für den Segment-Serializer. Erledigt ist es, wenn eine prozentuale Aufteilung ohne property erstellt werden kann und weiterhin den Identitätsschlüssel verwendet, während die Validierung der übrigen Bedingungen weiterhin abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
9.9k
Forks
658
Ø Merge
1 T. 15 Std.
Gemergte PRs (30 T.)
171

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus Flagsmith/flagsmith

Alle Issues in Flagsmith/flagsmith

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.