Skip to content

fix: use timezone-aware datetime in raw-SQL and endpoint queries - #1781

Open
Alicepoltora wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/datetime-naive-comparisons
Open

Alicepoltora wants to merge 2 commits into
genlayerlabs:v0.123-devfrom
Alicepoltora:fix/datetime-naive-comparisons

Conversation

@Alicepoltora

@Alicepoltora Alicepoltora commented Sep 27, 2026 •

Copy link
Copy Markdown

Problem

Three places used naive datetime.datetime.now() where timezone-aware datetimes are required:

  1. backend/database_handler/transactions_processor.py:1010 — recover_stuck_transactions() compares cutoff_time against Transactions.created_at which is DateTime(True) (tz-aware). Comparing naive vs tz-aware datetimes raises TypeError in Python 3.

  2. backend/node/base.py:808 — deploy_contract() falls back to naive datetime.now() which fails the assert transaction_datetime.tzinfo is not None in _run_genvm() whenever no sim_config.genvm_datetime override is provided.

  3. backend/protocol_rpc/endpoints.py:2663 — get_db_pool_status() returns a timestamp string without timezone info, inconsistent with all other Studio timestamps.

Fix

All three now use datetime.now(timezone.utc).

Tests

Regression tests verify the fixes work correctly.

Summary by CodeRabbit

  • Bug Fixes
    • Timestamps used for transaction processing and contract deployment now consistently use UTC, avoiding differences caused by local time zones.
    • Pool status and usage metrics now report timezone-aware UTC timestamps in ISO 8601 format when a timestamp is generated automatically.
    • This improves consistency when comparing timestamps across services and environments.

…e-aware datetime.now(timezone.utc)

datetime.utcnow() was deprecated in Python 3.12 and returns 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.
Three places used naive datetime.datetime.now() where timezone-aware
datetimes are required:

1. backend/database_handler/transactions_processor.py:1010
   recover_stuck_transactions() compares cutoff_time against
   Transactions.created_at which is DateTime(True) (tz-aware).
   Comparing naive vs tz-aware datetimes raises TypeError in Python 3.

2. backend/node/base.py:808
   deploy_contract() falls back to naive datetime.now() which fails
   the assert transaction_datetime.tzinfo is not None in _run_genvm().

3. backend/protocol_rpc/endpoints.py:2663
   get_db_pool_status() returns a timestamp string without timezone
   info, inconsistent with all other Studio timestamps.

All three now use datetime.now(timezone.utc).

Regression tests verify the fixes work correctly.
@github-actions
github-actions Bot changed the base branch from main to v0.123-dev September 27, 2026 18:22
@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: 0ed66e66-c064-4493-9899-8e272e792a63

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