From a8d8801f537cf3d47443793b0eaea8f8eee6b4ad Mon Sep 17 00:00:00 2001 From: RoomWithOutRoof Date: Wed, 15 Apr 2026 05:11:55 +0800 Subject: [PATCH] fix(dependencies): resolve forward ref in Annotated type_annotation When using 'from __future__ import annotations', the type inside Annotated remains as a string (forward reference). The fix resolves it using get_typed_annotation which calls evaluate_forwardref. Fixes: Can't use Annotated with ForwardRef (#13056) --- fastapi/dependencies/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 6b14dac8dc..6fbd787d74 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -411,6 +411,11 @@ def analyze_param( if get_origin(use_annotation) is Annotated: annotated_args = get_args(annotation) type_annotation = annotated_args[0] + # Resolve forward reference in type_annotation + if isinstance(type_annotation, str): + # Try to resolve using endpoint's globalns + globalns = getattr(call, "__globals__", {}) + type_annotation = get_typed_annotation(type_annotation, globalns) fastapi_annotations = [ arg for arg in annotated_args[1:]