Skip to content

fix(budget): log warning on timezone fallback to UTC#23018

Open
LeeJuOh wants to merge 4 commits intoBerriAI:mainfrom
LeeJuOh:fix/budget-timezone-fallback-warning
Open

fix(budget): log warning on timezone fallback to UTC#23018
LeeJuOh wants to merge 4 commits intoBerriAI:mainfrom
LeeJuOh:fix/budget-timezone-fallback-warning

Conversation

@LeeJuOh
Copy link
Contributor

@LeeJuOh LeeJuOh commented Mar 7, 2026

Relevant issues

Follow-up to #21754

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

🐛 Bug Fix

Changes

In #21754, the hardcoded timezone_map was replaced with ZoneInfo. On environments without the tzdata package, ZoneInfo throws an exception and silently falls back to UTC — operators have no way to tell their configured timezone is being ignored.

Rather than adding tzdata as a dependency, this PR adds a verbose_logger.warning() in the except block of _setup_timezone() to log when the fallback occurs.

  • litellm/litellm_core_utils/duration_parser.py: Add warning log on timezone load failure
  • No new dependencies, UTC fallback behavior preserved

LeeJuOh added 3 commits March 7, 2026 13:39
When ZoneInfo fails to load a configured timezone (e.g. missing tzdata),
the code silently falls back to UTC. Add a verbose_logger.warning() so
operators can see which timezone failed and how to fix it.
@vercel
Copy link

vercel bot commented Mar 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 7, 2026 5:26am

Request Review

@LeeJuOh
Copy link
Contributor Author

LeeJuOh commented Mar 7, 2026

@greptileai

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR adds a verbose_logger.warning() call in the except block of _setup_timezone() so operators are notified when their configured timezone cannot be loaded and UTC fallback is silently applied. No behavior changes are introduced — the UTC fallback is preserved exactly as before.

  • duration_parser.py: imports verbose_logger and emits a structured warning message including the offending timezone string and a hint to install tzdata.
  • test_duration_parser.py: adds test_invalid_timezone_logs_warning which patches the logger, calls get_next_standardized_reset_time with a bogus timezone, asserts warning is called exactly once, and verifies the timezone string appears in the second positional argument.
  • The existing test_edge_cases test exercises "NonExistentTimeZone" without mocking the logger; it will now trigger verbose_logger.warning() on each run. Since verbose_logger is controlled by litellm's log-level settings, this produces no output in default (non-verbose) test runs, but operators running tests with verbose logging enabled will see an expected warning line for that case.

Confidence Score: 5/5

  • This PR is safe to merge — it is a pure observability addition with no behavioral changes to the UTC fallback path.
  • The change is minimal (5 lines of production code), non-breaking, and the test correctly validates the new behavior. The fallback to UTC is preserved, and no new dependencies are introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/litellm_core_utils/duration_parser.py Adds verbose_logger import and emits a warning with the offending timezone string and tzdata hint when timezone loading fails; fallback behavior is unchanged.
tests/test_litellm/litellm_core_utils/test_duration_parser.py New test patches verbose_logger and verifies warning is called once with the timezone string as the second positional arg; pre-existing test_edge_cases will now silently invoke the real logger on each run.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["_setup_timezone(current_time, timezone_str)"] --> B{timezone_str is None?}
    B -- Yes --> C["tz = timezone.utc"]
    B -- No --> D["ZoneInfo(timezone_str)"]
    D -- Success --> E["tz = ZoneInfo result"]
    D -- Exception --> F["verbose_logger.warning(msg, timezone_str) 🆕"]
    F --> G["tz = timezone.utc  (fallback)"]
    C --> H["Convert current_time to tz"]
    E --> H
    G --> H
    H --> I["Return (current_time, tz)"]
Loading

Last reviewed commit: a9ef3cd

@LeeJuOh
Copy link
Contributor Author

LeeJuOh commented Mar 7, 2026

@greptileai

@LeeJuOh
Copy link
Contributor Author

LeeJuOh commented Mar 7, 2026

@krrishdholakia could you review this? Follow-up to #21754.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant