-
First Check
Commit to Help
Example Codefrom __future__ import annotations
from typing import Annotated, TypeAlias
from fastapi import Depends, FastAPI
app = FastAPI()
# dependency
async def some_value() -> int:
return 123
# This works.
DependedValue: TypeAlias = Annotated[int, Depends(some_value)]
# This won't work.
# type DependedValue = Annotated[int, Depends(some_value)]
@app.get('/')
async def get_with_dep(value: DependedValue) -> str:
print(f'{type(value) = !r}')
print(f'{value = !r}')
assert isinstance(value, int), '`value` should be an integer.'
assert value == 123, '`value` should be 123.'
return f'value: {value}' DescriptionWhen using the method in line 15: DependedValue: TypeAlias = Annotated[int, Depends(some_value)] to declare a type alias, FastAPI correctly interprets it and fills the However, when using the new type alias syntax introduced in Python 3.12 (line 18): type DependedValue = Annotated[int, Depends(some_value)] FastAPI interprets it as a URL query parameter and responds with HTTP 422 Unprocessable Entity when accessing Expected ResponseHTTP 200 OK
Actual ResponseHTTP 422 Unprocessable Entity
Operating SystemWindows Operating System DetailsNo response FastAPI Version0.104.1 Pydantic Version2.5.1 Python VersionPython 3.12.0 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I also encountered this problem 😥 |
Beta Was this translation helpful? Give feedback.
-
I've created #10719 to track this. |
Beta Was this translation helpful? Give feedback.
I've created #10719 to track this.