Repository navigation
fix(usage-metrics): replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) - #1780
Conversation
…e-aware datetime.now(timezone.utc)
datetime.utcnow() was removed in Python 3.12 and returned a naive datetime
(no timezone). _format_created_at() should emit ISO 8601 strings that carry
timezone info (+00:00) so the upstream metrics API can parse the offset
consistently with the rest of Studio.
The change replaces:
datetime.utcnow().isoformat()
with:
datetime.now(timezone.utc).isoformat()
Regression tests verify the returned string contains a timezone offset.
|
This PR targeted I retargeted it to |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
Problem
_format_created_at()useddatetime.utcnow()which is deprecated in Python 3.12 and returns a naive datetime (no timezone). The fallback ISO 8601 string had no offset, inconsistent with Studio's other timestamps.Fix
Replace
datetime.utcnow().isoformat()withdatetime.now(timezone.utc).isoformat()so the fallback carries a+00:00offset.Tests
tests/unit/test_usage_metrics_service.py:test_format_created_at_returns_utc_isoformatandtest_format_created_at_returns_original_datetime_isoformat— regression tests verify the returned string contains a timezone offset.Summary by CodeRabbit