Skip to content

Comments

fix(budget): log warning when ZoneInfo falls back to UTC#21879

Open
LeeJuOh wants to merge 3 commits intoBerriAI:litellm_oss_staging_02_22_2026from
LeeJuOh:fix/timezone-fallback-warning
Open

fix(budget): log warning when ZoneInfo falls back to UTC#21879
LeeJuOh wants to merge 3 commits intoBerriAI:litellm_oss_staging_02_22_2026from
LeeJuOh:fix/timezone-fallback-warning

Conversation

@LeeJuOh
Copy link

@LeeJuOh LeeJuOh commented Feb 22, 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

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 Feb 22, 2026

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

Project Deployment Actions Updated (UTC)
litellm Error Error Feb 22, 2026 7:10am

Request Review

@LeeJuOh
Copy link
Author

LeeJuOh commented Feb 22, 2026

@greptileai

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 22, 2026

Greptile Summary

This PR adds a verbose_logger.warning() call to the _setup_timezone() function in duration_parser.py so that when ZoneInfo fails to load a configured timezone (e.g., due to a missing tzdata package or an invalid timezone string), operators are informed via a warning log rather than silently falling back to UTC.

  • Added verbose_logger.warning() in the except block of _setup_timezone() with a message that includes the failed timezone string and hints at installing tzdata
  • Added a corresponding unit test using unittest.mock.patch to verify the warning is logged on invalid timezone input
  • No new dependencies; existing UTC fallback behavior is preserved
  • Import placed at module level, consistent with project conventions

Confidence Score: 5/5

  • This PR is safe to merge — it adds only a warning log line with no behavioral changes.
  • The change is minimal (4 lines of production code, 6 lines of test code), well-scoped, and non-functional — it only adds observability to an existing silent fallback. The warning uses lazy % formatting (correct for logging), the import is at module level per project conventions, and the test properly mocks the logger. No risk of regression.
  • No files require special attention

Important Files Changed

Filename Overview
litellm/litellm_core_utils/duration_parser.py Adds a verbose_logger.warning() call in the _setup_timezone() exception handler to log when timezone loading fails and falls back to UTC. Import added at module level. Minimal, well-scoped change.
tests/test_litellm/litellm_core_utils/test_duration_parser.py Adds a mock-based test verifying that verbose_logger.warning is called when an invalid timezone triggers the UTC fallback. No real network calls; uses unittest.mock.patch.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[get_next_standardized_reset_time] --> B[_setup_timezone]
    B --> C{timezone_str is None?}
    C -->|Yes| D[Use timezone.utc]
    C -->|No| E[ZoneInfo timezone_str]
    E -->|Success| F[Return tz]
    E -->|Exception| G["verbose_logger.warning() ⬅ NEW"]
    G --> H[Fallback to timezone.utc]
    D --> I[Convert current_time to target tz]
    F --> I
    H --> I
Loading

Last reviewed commit: 9397d3c

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@LeeJuOh
Copy link
Author

LeeJuOh commented Feb 22, 2026

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@LeeJuOh
Copy link
Author

LeeJuOh commented Feb 22, 2026

@krrishdholakia Could you review this when you have a chance? This is a 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