mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
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.
This commit is contained in:
parent
26bcafccb0
commit
a099e80618
1 changed files with 4 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue