Repository navigation
fix(usage-metrics): replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) - #1775
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()inUsageMetricsServiceuseddatetime.utcnow()to produce the fallback ISO 8601 timestamp whencreated_atisNone.datetime.utcnow()was deprecated in Python 3.12 and returns a naive datetime (no timezone). The returned string has no offset (e.g.2024-01-01T12:00:00.123456), which is inconsistent with every other timestamp in Studio (all others are+00:00-aware).Fix
Replace
datetime.utcnow().isoformat()withdatetime.now(timezone.utc).isoformat()so the fallback string carries a timezone offset (+00:00).Tests
tests/unit/test_usage_metrics_service.py: 2 new regression tests:test_format_created_at_returns_utc_isoformat— fails onmain(naive datetime has no+offset), passes with the fixtest_format_created_at_returns_original_datetime_isoformat— ensures datetime objects retain their original formatSummary by CodeRabbit