-
-
Notifications
You must be signed in to change notification settings - Fork 9k
How to define empty query parameters as missing? #1147
Copy link
Copy link
Closed
Labels
Description
First check
- I used the GitHub search to find a similar issue and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
Description
How can I make empty query parameters to be interpreted as missing value (and therefore default value is used) instead of empty string? For example, if I were to use optional int query param, empty string would find its way as value being passed and validation error for invalid int would be raised.
Additional context
Sample code:
from fastapi import APIRouter
router = APIRouter()
@router.get("/test/", tags=["test"])
def test(q: int = None):
return {"q": q}or
results in:
{
"detail": [
{
"loc": [
"query",
"q"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}Reactions are currently unavailable