FastUI
FastUI copied to clipboard
Type unions errors aren't showed in frontend
Imagine my form is:
class Form(BaseModel):
email: EmailStr | int
I know it doesn't make sense to have that union, but this is to just replicate the issue. Then on runtime, when I'm passing an invalid email address, I get this error:
{
"detail": {
"form": [
{
"type": "value_error",
"loc": [
"email",
"function-after[_validate(), str]"
],
"msg": "value is not a valid email address: The part after the @-sign is not valid. It should have a period."
},
{
"type": "int_parsing",
"loc": [
"email",
"int"
],
"msg": "Input should be a valid integer, unable to parse string as an integer"
}
]
}
}
Meanwhile, with None, that won't happen. loc would be an array with only "email".
As you can see, no error happened in first scenario with Union of int and email string, but in second scenario it was parsed correctly with Union of string email and None.