Flagsmith / Flagsmith/flagsmith

docs: SDK OpenAPI spec no longer documents the 2000-character trait value limit

Open
#7,995 2 comments 0 reactions 0 assignees View on GitHub
good first issue
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

### 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

The public SDK OpenAPI spec (sdk/openapi.yaml) advertises trait_value as an unconstrained string, but the API still rejects string trait values longer than 2000 characters.

The limit is enforced at runtime in api/environments/identities/traits/fields.py:27 via `TRAIT_STRING_VALUE_MAX_LENGTH = 2000:`

Value string is too long. Must be less than 2000 character

The spec previously documented it. `trait_value.anyOf` included `{type: string, maxLength: 2000}` — but the constraint was dropped in #6653 (flag-engine v10 upgrade, re-applied in #6741).
The trait schema now derives from `flag_engine.segments.types.ContextValue (None | int | float | bool | str)`, which carries no length constraint, so manage.py spectacular emits a plain string.

### Steps To Reproduce

1. Open the sdk_v1_post_identities reference (or sdk/openapi.yaml) and check `traits[].trait_value`, the string variant shows no maxLength.
2. Send a trait value of 2001 characters:
```
curl -X POST https://edge.api.flagsmith.com/api/v1/identities/ \
-H 'X-Environment-Key: ' \
-H 'Content-Type: application/json' \
-d "{\"identifier\": \"repro-user\", \"traits\": [{\"trait_key\": \"long\", \"trait_value\": \"$(printf 'a%.0s' {1..2001})\"}]}"
```
3. The API responds 400 Bad Request:

`{"traits": [{"trait_value": ["Value string is too long. Must be less than 2000 character"]}]}`

4. Per the published spec, this request is valid

### Expected behavior

`TraitInput.trait_value` and `Trait.trait_value` in the spec should document `maxLength: 2000` on the string variant, matching what the API enforces.

### Screenshots

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with api/environments/identities/traits/fields.py:27 and the generated schema in sdk/openapi.yaml; inspect how manage.py spectacular derives the trait_value schema from ContextValue. Verify both TraitInput.trait_value and Trait.trait_value show the string variant with maxLength: 2000, matching the API's rejection of a 2001-character value.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.