-
Notifications
You must be signed in to change notification settings - Fork 336
Closed
Milestone
Description
There is a bug with multi select fields when only one item is selected leading to an incorrect 422 error.
E.g., when selecting only one item for the "Select Multiple" select element on https://fastui-demo.onrender.com/forms/select, the POST request throws an unexpected 422 error:
{
"detail": {
"form": [
{
"type": "list_type",
"loc": [
"select_multiple"
],
"msg": "Input should be a valid list"
}
]
}
}This might be related to fastapi/fastapi#8741. A work-around, not elegant though, would be to add the following validation to SelectForm (https://github.com/pydantic/FastUI/blob/main/demo/forms.py):
@field_validator('select_multiple', mode='before')
@classmethod
def correct_list_fields(cls, value: List[str] | str) -> List[str]:
if isinstance(value, list):
return value
else:
return [value]Any thoughts on a neater solution?
virhilo
Metadata
Metadata
Assignees
Labels
No labels