Fix timezone handling in format_date_iso: ensure fallback to UTC for …#1590
Fix timezone handling in format_date_iso: ensure fallback to UTC for …#1590
Conversation
…invalid configurations
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Changes
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
server/utils/datetime_utils.py (1)
215-218: Narrow the broad exception catch in timezone resolution.At line 217,
except Exceptionis overly broad and can mask unrelated defects. Since this block only resolves timezone input, catch only the expected failures and keep the UTC fallback behavior.Proposed refactor
-from zoneinfo import ZoneInfo +from zoneinfo import ZoneInfo, ZoneInfoNotFoundError ... - try: - target_tz = conf.tz if isinstance(conf.tz, datetime.tzinfo) else ZoneInfo(conf.tz) - except Exception: - target_tz = datetime.UTC + try: + if isinstance(conf.tz, datetime.tzinfo): + target_tz = conf.tz + elif isinstance(conf.tz, str) and conf.tz: + target_tz = ZoneInfo(conf.tz) + else: + target_tz = datetime.UTC + except (AttributeError, TypeError, ZoneInfoNotFoundError): + target_tz = datetime.UTC🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@server/utils/datetime_utils.py` around lines 215 - 218, The broad except in the timezone resolution should be narrowed to only the expected errors when constructing a ZoneInfo from conf.tz; update the try/except around the target_tz assignment (the block that uses conf.tz and ZoneInfo(conf.tz)) to catch zoneinfo.ZoneInfoNotFoundError and other relevant construction errors (e.g., ValueError/TypeError) instead of Exception, and keep the existing fallback to datetime.UTC; ensure you reference ZoneInfoNotFoundError via the zoneinfo module or import it so the except clause is specific.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@server/utils/datetime_utils.py`:
- Around line 215-218: The broad except in the timezone resolution should be
narrowed to only the expected errors when constructing a ZoneInfo from conf.tz;
update the try/except around the target_tz assignment (the block that uses
conf.tz and ZoneInfo(conf.tz)) to catch zoneinfo.ZoneInfoNotFoundError and other
relevant construction errors (e.g., ValueError/TypeError) instead of Exception,
and keep the existing fallback to datetime.UTC; ensure you reference
ZoneInfoNotFoundError via the zoneinfo module or import it so the except clause
is specific.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 417724a8-5003-4822-82d1-9337a0eccbfa
📒 Files selected for processing (1)
server/utils/datetime_utils.py
…s for invalid configurations
…invalid configurations
Summary by CodeRabbit