-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
import logging
from typing import Annotated
from fastapi import Query
logger = logging.getLogger(__name__)
app = FastAPI()
@app.get("/")
def issue(latitude: Annotated[float, Query(ge=-90, le=90, description='Latitude in EPSG:4326')],):
logger.info(f"Latitude: {latitude}") DescriptionFastAPI won't start when using pydantic 2.1.0 and Annoted Query Operating SystemWindows Operating System DetailsNo response FastAPI Version0.100.0 Python Version3.11.4 Additional Context(.venv) C:\Users\Tomer\Desktop\issue>uvicorn main:app --reload |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Running the documentation example at the top of this page in Python 3.9 produces the same issue: from typing import Annotated, Union
from fastapi import FastAPI, Header
app = FastAPI()
@app.get("/items/")
async def read_items(user_agent: Annotated[Union[str, None], Header()] = None):
return {"User-Agent": user_agent} running with uvicorn:
|
Beta Was this translation helpful? Give feedback.
-
I experience the same issue when I run fastapi 0.100.0 from a |
Beta Was this translation helpful? Give feedback.
-
Same thing here, using depends also raises this error. from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordRequestForm
app = FastAPI()
def some_dependency(
form_data: OAuth2PasswordRequestForm = Depends(),
) -> OAuth2PasswordRequestForm:
if form_data.client_secret != "some_secret":
raise Exception("Invalid client secret")
return form_data
@app.post("/login")
def login(
form_data: OAuth2PasswordRequestForm = Depends(some_dependency),
) -> dict[str, str]:
return {"message": "message"}
|
Beta Was this translation helpful? Give feedback.
-
Pydantic 2.1.1 fixes this, and should be available now. |
Beta Was this translation helpful? Give feedback.
Pydantic 2.1.1 fixes this, and should be available now.