FastUI icon indicating copy to clipboard operation
FastUI copied to clipboard

Type unions errors aren't showed in frontend

Open ManiMozaffar opened this issue 11 months ago • 0 comments

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". Screenshot 2024-03-07 at 16 44 12

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.

Screenshot 2024-03-07 at 16 45 26

ManiMozaffar avatar Mar 07 '24 15:03 ManiMozaffar