From 3e93e805f630ddcb46f79be00c97dbe28d22b6d4 Mon Sep 17 00:00:00 2001 From: aayushbaluni <73417844+aayushbaluni@users.noreply.github.com> Date: Tue, 17 Mar 2026 23:34:30 +0530 Subject: [PATCH] fix: resolve ForwardRef in get_typed_annotation for Annotated+Depends (#13056) When using from __future__ import annotations with Annotated[Potato, Depends(...)], the annotation can reach analyze_param as a ForwardRef. Previously only str was resolved; ForwardRef was returned as-is, causing Depends to be missed and the param to be treated as a Query param. This led to PydanticUserError during OpenAPI schema generation. Extend get_typed_annotation to also resolve ForwardRef before returning. --- fastapi/dependencies/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 6b14dac8dc..e9064a04eb 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -245,6 +245,7 @@ def get_typed_signature(call: Callable[..., Any]) -> inspect.Signature: def get_typed_annotation(annotation: Any, globalns: dict[str, Any]) -> Any: if isinstance(annotation, str): annotation = ForwardRef(annotation) + if isinstance(annotation, ForwardRef): annotation = evaluate_forwardref(annotation, globalns, globalns) # ty: ignore[deprecated] if annotation is type(None): return None