From a099e8061830969e28e84a0c50d34cb638ad0848 Mon Sep 17 00:00:00 2001 From: IdoPort Date: Sun, 23 Aug 2026 13:12:40 +0300 Subject: [PATCH] refactor(proxy): rebuild app.routes in one expression instead of pop()/insert() Addresses Greptile review feedback on #38017: avoid in-place mutation of the shared FastAPI route list. Builds the reordered route list via unpacking and reassigns app.router.routes wholesale, rather than popping the appended route and inserting it back in place. --- .../proxy/pass_through_endpoints/pass_through_endpoints.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index 25a5f64f24e..dccc67ce47d 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -2582,14 +2582,16 @@ class SafeRouteAdder: before the first such generic route, so it is matched first instead. If no generic provider route is registered (e.g. a minimal deployment), leave the route appended -- current behavior is preserved as a safe fallback. + + Builds the reordered list in one expression and reassigns app.router.routes + wholesale, rather than mutating the existing list in place with pop()/insert(). """ routes = app.routes new_route = routes[-1] for index, route in enumerate(routes[:-1]): route_path = getattr(route, "path", None) if route_path and SafeRouteAdder._GENERIC_PROVIDER_PATH_MARKER in route_path: - routes.pop() - routes.insert(index, new_route) + app.router.routes = [*routes[:index], new_route, *routes[index:-1]] return @staticmethod