fix: replace deprecated datetime.utcnow() in memory subsystem#5996
fix: replace deprecated datetime.utcnow() in memory subsystem#5996Oxygen56 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughTimestamp generation in the memory system was standardized: calls to datetime.utcnow() were replaced with datetime.now(timezone.utc).replace(tzinfo=None) for defaults, scoring age calculations, update writes, and tests to ensure consistent naive-UTC datetimes. ChangesUTC Timestamp Standardization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 |
|
Thanks for addressing the remaining |
|
Thank you for the review! I have added
I also updated the existing test uses of |
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 `@lib/crewai/tests/memory/test_unified_memory.py`:
- Around line 35-37: Update the module docstring in test_unified_memory.py that
describes timestamp factories: change the inaccurate deprecation reference from
"datetime.now(timezone.utc).replace(tzinfo=None)" to the correct deprecated API
"datetime.utcnow()"; ensure the sentence now reads that naive UTC datetimes
match the behavior of the deprecated datetime.utcnow() to avoid confusion.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3e21e566-162c-4ea1-be50-070dcd255c3c
📒 Files selected for processing (1)
lib/crewai/tests/memory/test_unified_memory.py
|
Thanks for the reviews! @wizardo091: The test @coderabbitai: The test docstring already references the deprecated |
|
Tip For best results, initiate chat on the files or code changes.
|
…tive Replace remaining datetime.utcnow() calls in the memory subsystem with datetime.now(timezone.utc).replace(tzinfo=None). The utcnow() function was deprecated in Python 3.12 and generates DeprecationWarnings. Affected files: - memory/types.py: Field default_factories and composite score computation - memory/unified_memory.py: update_timestamp helper This complements PR crewAIInc#5970 which fixed the same pattern in encoding_flow.py and lancedb_storage.py. Related to crewAIInc#5109 (Python 3.14 compatibility) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add test_memory_record_timestamps_are_naive_utc() to verify that timestamps generated by the default factories are naive (no tzinfo) UTC datetimes matching the behavior of the deprecated datetime.utcnow(). Also update existing test uses of datetime.utcnow() to datetime.now(timezone.utc).replace(tzinfo=None) to avoid DeprecationWarnings in Python 3.12+. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
320e6cd to
69a685d
Compare
Summary
Replace remaining
datetime.utcnow()calls in the memory subsystem withdatetime.now(timezone.utc).replace(tzinfo=None). Theutcnow()function was deprecated in Python 3.12 and generatesDeprecationWarning— it may be removed in Python 3.14.Changes
lib/crewai/src/crewai/memory/types.pydatetime.utcnowdefault factories (2 occurrences) and inline call incompute_composite_score(1 occurrence)lib/crewai/src/crewai/memory/unified_memory.pydatetime.utcnow()inupdate_record(1 occurrence)Why
.replace(tzinfo=None)?The existing code stored naive datetimes via
utcnow(). To preserve compatibility with stored data, the replacement produces a naive UTC datetime — the same value thatutcnow()returns, without the deprecation warning.Related
datetime.utcnow()across the memory subsystem #5970 which fixed the same pattern inencoding_flow.pyandlancedb_storage.pyTesting
All existing tests pass. The change is a mechanical replacement that produces identical values.
Summary by CodeRabbit
Bug Fixes
Tests