Skip to content

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

Closed
LeeJuOh wants to merge 3 commits intoBerriAI:mainfrom
LeeJuOh:fix/timezone-fallback-warning
Closed

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

Conversation

@LeeJuOh
Copy link
Contributor

@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

@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 Ready Ready Preview, Comment Feb 24, 2026 4:09pm

Request Review

@LeeJuOh
Copy link
Contributor 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 in _setup_timezone() when ZoneInfo fails to load a configured timezone and silently falls back to UTC. This addresses an observability gap from #21754 where ZoneInfo replaced the hardcoded timezone map — on environments without the tzdata package, the fallback was completely silent, leaving operators unaware their timezone configuration was being ignored.

  • Adds a warning log in the except block of _setup_timezone() with an actionable message suggesting the operator check the timezone string and tzdata package installation
  • Adds a mock-based unit test verifying the warning is emitted for invalid timezones
  • No new dependencies; UTC fallback behavior preserved
  • Import placed at module level, consistent with project conventions

Confidence Score: 5/5

  • This PR is safe to merge — it only adds a warning log in an existing fallback path with no behavioral changes.
  • The change is minimal and well-scoped: a single warning log added to an existing except block. No logic changes, no new dependencies, no risk of regression. The fallback behavior is preserved exactly as before. The test correctly verifies the new logging behavior using mocks.
  • 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() except block to log when timezone loading fails and UTC fallback occurs. Clean, minimal change with correct lazy string formatting.
tests/test_litellm/litellm_core_utils/test_duration_parser.py Adds a mock-based test verifying the warning log is emitted when an invalid timezone is provided. No real network calls; consistent with existing test patterns.

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["tz = ZoneInfo(timezone_str)"]
    D -- Success --> E["Convert current_time to tz"]
    D -- Exception --> F["⚠️ verbose_logger.warning\n'Failed to load timezone...'"]
    F --> G["tz = timezone.utc (fallback)"]
    C --> E
    G --> E
    E --> H["Return (current_time, tz)"]
Loading

Last reviewed commit: 2a35755

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
Contributor 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
Contributor Author

LeeJuOh commented Feb 22, 2026

@krrishdholakia Could you review this when you have a chance? This is a follow-up to #21754.

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.
@LeeJuOh LeeJuOh force-pushed the fix/timezone-fallback-warning branch from 9397d3c to 2a35755 Compare February 24, 2026 16:08
@LeeJuOh LeeJuOh changed the base branch from litellm_oss_staging_02_22_2026 to main February 24, 2026 16:08
@LeeJuOh
Copy link
Contributor Author

LeeJuOh commented Feb 24, 2026

@greptileai

@LeeJuOh
Copy link
Contributor Author

LeeJuOh commented Feb 24, 2026

@krrishdholakia Rebased onto latest main and updated the PR base branch (the previous target litellm_oss_staging_02_22_2026 was already merged). Could you review this when you have a chance?

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

@shin-bot-litellm
Copy link
Collaborator

Review

1. Does this PR fix the issue it describes?
Yes. Follow-up to #21754 — adds warning log when ZoneInfo falls back to UTC (missing tzdata package). Operators now have visibility into timezone issues.

2. Has this issue already been solved elsewhere?
No — the silent fallback was problematic.

3. Are there other PRs addressing the same problem?
No duplicates found.

4. Are there other issues this potentially closes?
Any reports of budget reset times being wrong due to unnoticed UTC fallback.

✅ LGTM — minimal change, no new dependencies, preserves fallback behavior with observability.

@LeeJuOh LeeJuOh closed this Mar 7, 2026
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.

2 participants