Repository navigation
fix(usage-metrics): replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) - #1779
Closed
Alicepoltora wants to merge 1 commit into
Closed
Alicepoltora wants to merge 1 commit into
Alicepoltora wants to merge 1 commit into
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.
Contributor
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
✨ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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