Skip to content

fix: replace deprecated datetime.utcnow() with timezone-aware alternative#2540

Open
nightcityblade wants to merge 2 commits intotopoteretes:devfrom
nightcityblade:fix/deprecated-utcnow-remaining
Open

fix: replace deprecated datetime.utcnow() with timezone-aware alternative#2540
nightcityblade wants to merge 2 commits intotopoteretes:devfrom
nightcityblade:fix/deprecated-utcnow-remaining

Conversation

@nightcityblade
Copy link
Copy Markdown

@nightcityblade nightcityblade commented Apr 3, 2026

Description

Replace remaining datetime.utcnow() calls with datetime.now(timezone.utc) across 4 files. datetime.utcnow() is deprecated since Python 3.12 and returns naive datetimes that can cause subtle timezone bugs.

Files changed:

  • cognee/get_token.py — JWT expiry timestamp
  • cognee/eval_framework/modal_run_eval.py — eval timestamp
  • cognee/infrastructure/databases/cache/redis/RedisAdapter.py — cache entry timestamp
  • cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py — cache entry timestamp

Acceptance Criteria

  • No remaining utcnow() calls in the codebase
  • All timestamps are now timezone-aware (UTC)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Pre-submission Checklist

  • I have tested my changes thoroughly before submitting this PR
  • This PR contains minimal changes necessary to address the issue/feature
  • My code follows the project's coding standards and style guidelines
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if applicable)
  • All new and existing tests pass
  • I have searched existing PRs to ensure this change hasn't been submitted already
  • I have linked any relevant issues in the description
  • My commits have clear and descriptive messages

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.

Summary by CodeRabbit

  • Chores
    • Standardized timestamp handling to use timezone-aware UTC datetimes across the app, affecting filename generation, token expiry timestamps, and cache/redis records.
    • Timestamps now consistently include explicit UTC information while preserving existing timestamp formats and public behaviors. No public interfaces were changed.

…tive

Replace remaining datetime.utcnow() calls with
datetime.now(timezone.utc) across 4 files:
- cognee/get_token.py (JWT expiry)
- cognee/eval_framework/modal_run_eval.py (timestamp)
- cognee/infrastructure/databases/cache/redis/RedisAdapter.py
- cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py

datetime.utcnow() is deprecated since Python 3.12 (PEP 587)
and returns naive datetimes that can cause subtle timezone bugs.
@pull-checklist
Copy link
Copy Markdown

pull-checklist bot commented Apr 3, 2026

Please make sure all the checkboxes are checked:

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have added end-to-end and unit tests (if applicable).
  • I have updated the documentation and README.md file (if necessary).
  • I have removed unnecessary code and debug statements.
  • PR title is clear and follows the convention.
  • I have tagged reviewers or team members for feedback.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Hello @nightcityblade, thank you for submitting a PR! We will respond as soon as possible.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: db02fc29-bbaa-49cd-ae26-03eb1e647bfe

📥 Commits

Reviewing files that changed from the base of the PR and between fa37428 and a72a7ef.

📒 Files selected for processing (1)
  • cognee/get_token.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • cognee/get_token.py

Walkthrough

Replaced timezone-naive datetime.utcnow() calls with timezone-aware datetime.now(datetime.timezone.utc) across four files, adjusting imports where needed. Output formats and filename/timestamp string formats were preserved.

Changes

Cohort / File(s) Summary
Timezone-aware UTC timestamp updates
cognee/eval_framework/modal_run_eval.py, cognee/get_token.py, cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py, cognee/infrastructure/databases/cache/redis/RedisAdapter.py
Replaced timezone-naive datetime.utcnow() with timezone-aware datetime.now(datetime.timezone.utc) for timestamp generation (filenames, JWT exp claim, cache QA entry timestamps). Updated imports to include timezone where required; no other logic or public APIs changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

core-team

Suggested reviewers

  • Vasilije1990
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: replacing deprecated datetime.utcnow() calls with timezone-aware alternatives.
Description check ✅ Passed The description covers all required template sections including clear description, acceptance criteria, type of change, and pre-submission checklist items.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cognee/get_token.py`:
- Line 13: The file fails ruff formatting; run the formatter and commit the
result: execute `ruff format cognee/get_token.py` (and optionally `ruff check
cognee/get_token.py --line-length 100`) to fix formatting and import/style
issues in the token creation code (the dict containing the "exp" datetime), then
add and commit the reformatted file so the CI passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0828fab1-797a-4910-9a2a-493dd7f1395a

📥 Commits

Reviewing files that changed from the base of the PR and between 863ed64 and fa37428.

📒 Files selected for processing (4)
  • cognee/eval_framework/modal_run_eval.py
  • cognee/get_token.py
  • cognee/infrastructure/databases/cache/fscache/FsCacheAdapter.py
  • cognee/infrastructure/databases/cache/redis/RedisAdapter.py

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