I'm starting to learn Python and FastAPI but I encountered a weird thing. When I set
@app.get("/test")
async def test(q: str = Query(min_length=3)):
return q
it correctly checks if q has at least 3 characters, but when I do it as suggested in docs
@app.get("/test")
async def test(q: Annotated[str, Query(min_length=3)]):
return q
it ignores the min_length
rule and only checks if q is present, is there any reason why it happens? I'm using Python 3.10.10 and FastAPI 0.94.1
I also had this issue. The Annotate
feature only works in FastAPI version 0.95+.
Just do
pip install --upgrade fastapi
to upgrade to the latest version. That should solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With