Use the const value when a literal branch is selected in a schema form - #22911
Conversation
…a form A pydantic Literal in a union becomes an anyOf definition with a const and no default. The React schema form left that branch empty, so a required parameter stayed invalid when the deployment default was another type in the union. The form now emits the const as the value for that branch, and branch selection prefers a definition whose const matches the value over a definition that only matches its type. OSS-8166 Co-authored-by: Alexander Streed <alex.s@prefect.io>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Runtime verification of the deployment Run form (ui-v2) Tested against a local Prefect server with the reporter's deployment ( Before (base commit): the literal branch stays empty, and the form sends
|
closes #22909
This PR makes the React schema form use the const value of a union branch.
Pydantic gives a
Literalin a union ananyOfdefinition with aconstand nodefault:{ "anyOf": [ { "items": { "type": "string" }, "type": "array" }, { "const": "bar", "type": "string" }, { "type": "null" } ] }The user cannot type the value of a
const, and the form did not supply it. When the user selected the literal branch, the value stayed empty. The form did not show an error, and it sentnullfor the parameter. Thus the user could not give the literal value, and the run got the wrong value.Details
The form now does two things:
constof that branch.constis equal to the value, before a definition that only has the same type as the value. A union withLiteral["bar"]andstrin it now shows the literal branch for the value"bar", and thestrbranch for other strings.Tests:
ui-v2/src/components/schemas/schema-form-input-any-of.test.tsx— the form emits"bar"when the user selects the literal branch oflist[str] | Literal["bar"] | None.ui-v2/src/components/schemas/utilities/getIndexForAnyOfPropertyValue.test.ts— index resolution prefers theconstmatch, and keeps the type match when noconstis equal to the value.The behavior is also verified in a browser against a local server. See the comment below.
The same defect is in the Vue schema form. The change for the V1 UI is in PrefectHQ/prefect-ui-library#3133, and the change for the Cloud UI is in PrefectHQ/nebula-ui#7070.
Checklist
<link to issue>"mint.json.Link to Devin session: https://app.devin.ai/sessions/c7d997cb25b0431786119152836c2251