From b2798dab90507ce04b98233c21fd77420061d989 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Fri, 13 Mar 2026 15:32:18 +0100 Subject: [PATCH] provide a default name for an endpoint without __name__ attribute --- fastapi/openapi/utils.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 4a9428f7b3..298c04c7fe 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -245,10 +245,8 @@ def get_openapi_operation_metadata( operation["description"] = route.description operation_id = route.operation_id or route.unique_id if operation_id in operation_ids: - message = ( - f"Duplicate Operation ID {operation_id} for function " - + f"{route.endpoint.__name__}" # ty: ignore[unresolved-attribute] - ) + endpoint_name = getattr(route.endpoint, "__name__", "") + message = f"Duplicate Operation ID {operation_id} for function {endpoint_name}" file_name = getattr(route.endpoint, "__globals__", {}).get("__file__") if file_name: message += f" at {file_name}"