mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
fix(proxy): quarantine only unparseable duration strings
Integer durations stay a per-row failure. 1hr and fortnightly now raise instead of resetting at the next midnight. Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.com>
This commit is contained in:
parent
e5afb31420
commit
314b581f10
2 changed files with 5 additions and 3 deletions
|
|
@ -368,7 +368,9 @@ def _count_advanced(reset_ats: Iterable[object], cutoff: datetime) -> int:
|
|||
|
||||
def _try_compute_budget_reset_at(duration: object, settings: BudgetResetSettings) -> datetime | None:
|
||||
if not isinstance(duration, str):
|
||||
return None
|
||||
raise ValueError(
|
||||
f"Invalid budget_duration {duration!r}. Use the <int><unit> format (e.g. '1h', '7d', '30d', '1mo')."
|
||||
)
|
||||
try:
|
||||
return compute_budget_reset_at(budget_duration=duration, settings=settings)
|
||||
except ValueError:
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@ class TestWordFormBudgetDurations(unittest.TestCase):
|
|||
|
||||
def test_unparseable_duration_raises_instead_of_midnight_fallback(self):
|
||||
base_time = datetime(2023, 5, 15, 15, 0, 0, tzinfo=timezone.utc)
|
||||
for duration in ("", " ", "garbage", "1x", "1dinvalid"):
|
||||
for duration in ("", " ", "garbage", "1x", "1dinvalid", "1hr", "fortnightly"):
|
||||
with self.assertRaises(ValueError) as ctx:
|
||||
get_next_standardized_reset_time(duration, base_time, "UTC")
|
||||
self.assertIn("Invalid budget_duration", str(ctx.exception))
|
||||
|
|
@ -348,7 +348,7 @@ class TestWordFormBudgetDurations(unittest.TestCase):
|
|||
class TestGetBudgetWindowStart(unittest.TestCase):
|
||||
def test_window_start_is_the_previous_reset_on_the_same_schedule(self):
|
||||
created_at: Final = datetime(2024, 10, 1, 0, 30, tzinfo=timezone.utc)
|
||||
durations: Final = "1d 24h daily 7d weekly 2w 10d 30d monthly 1mo 4h 5h 30m 45s 1hr fortnightly".split()
|
||||
durations: Final = "1d 24h daily 7d weekly 2w 10d 30d monthly 1mo 4h 5h 30m 45s".split()
|
||||
for duration in durations:
|
||||
with self.subTest(duration=duration):
|
||||
reset_at = get_next_standardized_reset_time(duration, created_at, "UTC")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue