Skip to content

fix(usage-metrics): replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) - #1780

Open
Alicepoltora wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/usage-metrics-datetime-utcnow
Open

Alicepoltora wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/usage-metrics-datetime-utcnow

Conversation

@Alicepoltora

@Alicepoltora Alicepoltora commented Sep 27, 2026 •

Copy link
Copy Markdown

Problem

_format_created_at() used datetime.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() with datetime.now(timezone.utc).isoformat() so the fallback carries a +00:00 offset.

Tests

  • tests/unit/test_usage_metrics_service.py: test_format_created_at_returns_utc_isoformat and test_format_created_at_returns_original_datetime_isoformat — regression tests verify the returned string contains a timezone offset.

Summary by CodeRabbit

  • Bug Fixes
    • Missing creation times now produce ISO 8601 timestamps with an explicit UTC offset. Existing UTC timestamps retain their representation.

…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.
@github-actions
github-actions Bot changed the base branch from main to v0.123-dev September 27, 2026 18:21
@github-actions

Copy link
Copy Markdown
Contributor

This PR targeted main, which is only the default/static branch.

I retargeted it to v0.123-dev, the active development branch. Pushes to v0.123-dev automatically fast-forward main.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4050008a-4855-459e-838d-bbe928053c2f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant