-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Closed
Description
Privileged issue
- I'm @tiangolo or he asked me directly to create an issue here.
Issue Content
FastAPI 0.95.0 introduced Annotated as a way to create dependencies (https://fastapi.tiangolo.com/release-notes/#0950).
Before 0.95.0, it was possible to use Response as a type hint for dependencies. After that, it was not possible anymore.
- See Cannot specify `Depends` for type Response, yet docs imply you can? #9897 for more details - Thanks @holyoaks for the report.
Example that worked before:
from typing import Annotated
from fastapi import FastAPI, Response, Depends
app = FastAPI()
def set_no_cache_headers(response: Response) -> Response:
response.headers["Potato"] = "potato"
return response
@app.get("/")
def testing_response(response: Response = Depends(set_no_cache_headers)):
return {}As a workaround today, if you remove the Response type hint, it works as expected:
@app.get("/")
def testing_response(response = Depends(set_no_cache_headers)):
return {}The Annotated way also doesn't work:
@app.get("/")
def testing_response(response: Annotated[Response, Depends(set_no_cache_headers)]):
return {}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels