fix: replace deprecated datetime.utcnow() with datetime.now(UTC) throughout#659
fix: replace deprecated datetime.utcnow() with datetime.now(UTC) throughout#659neuron-tech-ai wants to merge 2 commits into
Conversation
Python 3.12 deprecates datetime.utcnow() with a DeprecationWarning and
it will be removed in a future release. Replace all call-site usages in
services, routes, and utils with datetime.now(UTC), and replace the
SQLAlchemy ORM column defaults (which used the bare function reference
datetime.utcnow) with lambda: datetime.now(UTC) so that the returned
objects are timezone-aware and consistent with Python best practice.
Affected: database/models.py, services/{stories,history,profiles,
channels,export_import}.py, routes/{profiles,tasks}.py, utils/tasks.py
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR migrates all timestamp handling from naive UTC ( ChangesTimezone-aware UTC timestamp migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/services/export_import.py`:
- Line 435: The call datetime.now(UTC) will raise NameError because UTC isn't
defined; import timezone from the datetime module and use it explicitly (i.e.,
replace or update the usage of datetime.now(UTC) to datetime.now(timezone.utc)
and add a matching import such as "from datetime import timezone") so the
timezone is defined; locate the occurrence of datetime.now(UTC) in
export_import.py and add the import near the existing datetime import.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 88385247-23e6-4a7e-aa56-acc6b3d708cc
📒 Files selected for processing (9)
backend/database/models.pybackend/routes/profiles.pybackend/routes/tasks.pybackend/services/channels.pybackend/services/export_import.pybackend/services/history.pybackend/services/profiles.pybackend/services/stories.pybackend/utils/tasks.py
The function-local import was missing UTC, causing NameError at runtime when datetime.now(UTC) was called.
|
Addressed the CodeRabbit review comment: Missing |
datetime.utcnow()is deprecated in Python 3.12 and raisesDeprecationWarning. It also returns a naive datetime (no timezone info), which is a footgun when comparing with timezone-aware datetimes.Replaces all usages across the codebase with
datetime.now(UTC), which returns a timezone-aware UTC datetime and is the correct approach going forward. Pure mechanical replacement — no behavior change.Summary by CodeRabbit
Release Notes
Bug Fixes