mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(router): stop fallback lookups from mutating the router fallbacks config
get_fallback_model_group resolved a bare-string fallback by popping it out of the fallbacks list it was handed. That list is frequently the live router.fallbacks config, so a single lookup permanently removed the entry and the configured fallback stopped applying to later requests until restart. The pop also ran inside enumerate(), shifting indices and skipping an adjacent string fallback. Read the item instead of popping it, and add a regression test that fails on the old mutating behavior
This commit is contained in:
parent
dc6611b4f7
commit
0159f7ae1b
2 changed files with 18 additions and 2 deletions
|
|
@ -72,7 +72,7 @@ def get_fallback_model_group(
|
|||
elif list(item.keys())[0] == "*": # check generic fallback
|
||||
generic_fallback_idx = idx
|
||||
elif isinstance(item, str):
|
||||
fallback_model_group = [fallbacks.pop(idx)] # returns single-item list
|
||||
fallback_model_group = [item]
|
||||
## if none, check for generic fallback
|
||||
if fallback_model_group is None:
|
||||
if stripped_model_fallback is not None:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import json
|
|||
|
||||
import pytest
|
||||
|
||||
from litellm.router_utils.fallback_event_handlers import run_async_fallback
|
||||
from litellm.router_utils.fallback_event_handlers import (
|
||||
get_fallback_model_group,
|
||||
run_async_fallback,
|
||||
)
|
||||
|
||||
|
||||
class StreamingWrapper:
|
||||
|
|
@ -137,3 +140,16 @@ async def test_run_async_fallback_skips_original_model_group():
|
|||
)
|
||||
|
||||
assert response._hidden_params["additional_headers"]["x-litellm-attempted-fallbacks"] == 1
|
||||
|
||||
|
||||
def test_get_fallback_model_group_does_not_mutate_fallbacks():
|
||||
"""A string fallback must be resolved without mutating the caller's
|
||||
fallbacks list, which is the live router config shared across requests."""
|
||||
fallbacks = [{"gpt-3.5-turbo": ["claude-3-haiku"]}, "gpt-4o-mini"]
|
||||
|
||||
fallback_model_group, _ = get_fallback_model_group(
|
||||
fallbacks=fallbacks, model_group="unmatched-model"
|
||||
)
|
||||
|
||||
assert fallback_model_group == ["gpt-4o-mini"]
|
||||
assert fallbacks == [{"gpt-3.5-turbo": ["claude-3-haiku"]}, "gpt-4o-mini"]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue