From 79225822bc07badcc541ded09df9c3da86e713d0 Mon Sep 17 00:00:00 2001 From: Contributor Date: Sun, 12 Apr 2026 18:20:22 +0530 Subject: [PATCH] fix: preserve backwards compatibility in generate_unique_id for route creation When generate_unique_id is called during route creation without a method parameter, use the first method only (original behavior) to avoid breaking existing tests. When called with a specific method parameter from openapi utils, generate unique operation IDs per HTTP method to fix duplicate operation IDs bug. --- fastapi/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fastapi/utils.py b/fastapi/utils.py index 2740a15fcf..18a76003f3 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -102,9 +102,8 @@ def generate_unique_id(route: APIRoute, method: str | None = None) -> str: # Include the specific method being generated operation_id = f"{operation_id}_{method.lower()}" else: - # When no specific method is provided, include all methods (for backwards compatibility) - methods_str = "_".join(sorted(m.lower() for m in route.methods)) - operation_id = f"{operation_id}_{methods_str}" + # When no specific method is provided, use the first method for backwards compatibility + operation_id = f"{operation_id}_{list(route.methods)[0].lower()}" return operation_id