I used the GitHub search to find a similar question 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.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to FastAPI but to Pydantic.
I already checked if it is not related to FastAPI but to Swagger UI.
I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
I commit to help with one of those options 👆
Example Code
from __future__ importannotationsfromtypingimportAnnotated, TypeAliasfromfastapiimportDepends, FastAPIapp=FastAPI()
# dependencyasyncdefsome_value() ->int:
return123# This works.DependedValue: TypeAlias=Annotated[int, Depends(some_value)]
# This won't work.# type DependedValue = Annotated[int, Depends(some_value)]@app.get('/')asyncdefget_with_dep(value: DependedValue) ->str:
print(f'{type(value) = !r}')
print(f'{value= !r}')
assertisinstance(value, int), '`value` should be an integer.'assertvalue==123, '`value` should be 123.'returnf'value: {value}'
Not just dependencies, any kind of annotations stops working. For example:
type DateInBody=Annotated[date, Body(embed=True)]
@app.post('/api/endpoint')asyncdefapi_endpoint(
*,
my_date: DateInBody,
) ->date:
returndate
/api/endpoint has my_date parameter in request query, not in its body. Removing type before DateInBody definitions solves the issue: my_date parameter is now expected in request body.
Activity
dev-loki commented on Feb 11, 2024
I'm in search for my first fastapi contribution and as such I might ask some not so clever questions.
To this problem:
Wouldn't this be solved by unacking the typing.TypeAliasType via using it's __value__ attribute?
This can done before dependencies.utils:328:
I can work in python<3.12 with something like:
(more elegant approach appreciated)
Best regards and happy weekend,
Torsten Zielke
imacat commented on Mar 9, 2024
Confirm this issue.
With Python 3.12 new type syntax, FastAPI ignores the dependency annotation.
from typing import Annotated, TypeAlias from fastapi import FastAPI, Query, Depends app: FastAPI = FastAPI() def get_name1(name1: Annotated[str, Query(title="Name")]) -> str: return f"Name: {name1}" def get_name2(name2: Annotated[str, Query(title="Name")]) -> str: return f"Name: {name2}" Name1: TypeAlias = Annotated[str, Depends(get_name1)] type Name2 = Annotated[str, Depends(get_name2)] @app.get("/") async def test(name1: Name1, name2: Name2) -> dict[str, str]: return {"name1": name1, "name2": name2}The dependency get_name2 is ignored.
user@host ~ % curl -X 'GET' 'http://localhost:8000/?name1=betty1&name2=betty2' -H 'accept: application/json' {"name1":"Name: betty1","name2":"betty2"} user@host ~ %declaresub commented on Apr 30, 2024
I too keep running into this issue.
Prometheus3375 commented on Nov 26, 2024
Not just dependencies, any kind of annotations stops working. For example:
/api/endpoint has my_date parameter in request query, not in its body. Removing type before DateInBody definitions solves the issue: my_date parameter is now expected in request body.
jmaillefaud commented on Mar 27, 2025
For reference, here is the link to the python type documentation on the three modern ways of defining type aliases: https://typing.python.org/en/latest/spec/aliases.html
YuriiMotov commented on May 28, 2025
Related discussions:
uriyyo commented on Oct 5, 2025
For those still waiting for the official FastAPI fix - you can use fastapi-backports until the official release.
Brings multiple Query models and PEP 695 type alias support to FastAPI until it is officially supported:
https://github.com/uriyyo/fastapi-backports
Usage example:
tiangolo commented on Feb 5, 2026
This should be solved by #13920, available in FastAPI 0.128.2, released in the next few hours. 🎉