Skip to content

Playground API rejects a context without appName, which the docs say the playground fills in for you #12564

Description

@truecourse-agent

Summary

The playground documentation lists appName as an implicit context field that the playground fills in for you. POST /api/admin/playground rejects a request without it with 400 BadDataError. The default exists only in the Admin UI, which injects appName: 'playground' before it posts; the API applies no default.

The sibling field in the same documented list, currentTime, is defaulted server-side, which is what makes this look like an oversight rather than a deliberate difference.

Tested on main at 3d91a51635859f13a5bc23547d323c19718629fb (unleash-server 8.1.0), OSS, stock config, Postgres 15, admin token.

What the docs say

https://docs.getunleash.io/concepts/playground, "Implicit context fields":

You can add any fields you want to the context used for the evaluation, and you can also leave out any fields you want. However, there are some fields that will be set for you if don't provide them:

  • appName: Unleash clients all require an appName to start up. If you do not provide an appName, the playground will assign a default value to this property instead.
  • currentTime: The currentTime property of the Unleash context gets auto-populated with the current time. You can override this manually by providing a value of your own.

Reproduction

Setup: one flag tcref-appname with a 100% flexibleRollout strategy, development enabled.

Control — with appName, the evaluation works:

POST /api/admin/playground
body: {"environment":"development","context":{"appName":"tcref","userId":"alice"}}
-> 200
{"input":{"environment":"development","context":{"appName":"tcref","userId":"alice"}},
 "features":[{"isEnabled":true,"isEnabledInCurrentEnvironment":true, ... "name":"tcref-appname", ...}]}

The same request with appName left out:

POST /api/admin/playground
body: {"environment":"development","context":{"userId":"alice"}}
-> 400
{"id":"200cf8b4-59bb-45cc-bae7-1ebd869ff72b","name":"BadDataError",
 "message":"Request validation failed: your request body or params contain invalid data. Refer to the `details` list for more information.",
 "details":[{"path":"/body/context/appName","message":"The `/body/context/appName` property is required. It was not present on the data you sent."}]}

Where the difference comes from

  • src/lib/openapi/spec/sdk-context-schema.ts:7required: ['appName'], so the request never reaches the service.

  • frontend/src/component/playground/Playground/AdvancedPlayground.tsx:211-214 — the Admin UI supplies the default itself before posting:

    const parsedContext = {
        appName: 'playground',
        ...JSON.parse(context || '{}'),
    };
  • currentTime, by contrast, is defaulted on the server: src/lib/features/playground/feature-evaluator/constraint.ts:119-121 falls back to new Date() when the context carries no currentTime.

So of the two fields documented as "set for you", one is handled by the server and one only by one particular client.

Either fix works

Default appName in the playground service (dropping it from sdkContextSchema's required, which would also let the Admin UI stop special-casing it), or amend the docs to say that the default is applied by the Admin UI and that the API requires appName. The first matches what the page currently promises.

Suggested labels: bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions