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

Abierto Apto para principiantes
#9,152 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
api

Línea de trabajo

Empieza en api/segments/serializers.py, en SegmentSerializer._get_clean_rules_and_conditions, y después revisa la validación de las condiciones y el manejo de la división porcentual en flag_engine/segments/evaluator.py. Reproduce la solicitud a la Admin API del issue y revisa las pruebas existentes del serializador de segmentos. Se considera terminado cuando se puede crear una división porcentual sin property y esta sigue usando la clave de identidad, mientras la validación de las demás condiciones sigue cubierta.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
9.9k
Forks
658
Merge medio
1 d 15 h
PR fusionados (30 d)
171

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Flagsmith/flagsmith

Todos los issues de Flagsmith/flagsmith

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.