Skip to content

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

Open
fazalpsinfo-cmyk wants to merge 2 commits into
crewAIInc:mainfrom
fazalpsinfo-cmyk:fix-datetime-utcnow
Open

fix: replace deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc)#6581
fazalpsinfo-cmyk wants to merge 2 commits into
crewAIInc:mainfrom
fazalpsinfo-cmyk:fix-datetime-utcnow

Conversation

@fazalpsinfo-cmyk

@fazalpsinfo-cmyk fazalpsinfo-cmyk commented Jul 17, 2026

Copy link
Copy Markdown

Replace deprecated datetime.utcnow() with datetime.now(timezone.utc) across the memory module for Python 3.12+ compatibility.

datetime.utcnow() is deprecated since Python 3.12 (PEP 623).

Files changed:

  • lib/crewai/src/crewai/memory/unified_memory.py
  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py
  • lib/crewai/src/crewai/memory/types.py
  • lib/crewai/src/crewai/memory/encoding_flow.py
  • lib/crewai/tests/memory/test_unified_memory.py

Support this work: https://buymeacoffee.com/muhamedfazalps

…e.now(timezone.utc)

Replaced all instances of deprecated datetime.utcnow() with
datetime.now(timezone.utc) across 4 memory module files.

Affected files:
- lib/crewai/src/crewai/memory/unified_memory.py
- lib/crewai/src/crewai/memory/storage/lancedb_storage.py
- lib/crewai/src/crewai/memory/types.py
- lib/crewai/src/crewai/memory/encoding_flow.py
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Memory timestamp creation, parsing, storage, update flows, and recency calculations now use timezone-aware UTC datetimes.

Changes

Memory timestamp consistency

Layer / File(s) Summary
Timestamp defaults and scoring
lib/crewai/src/crewai/memory/types.py
MemoryRecord timestamp defaults and composite score age calculations now use timezone-aware UTC datetimes.
Timestamp propagation and storage
lib/crewai/src/crewai/memory/unified_memory.py, lib/crewai/src/crewai/memory/encoding_flow.py, lib/crewai/src/crewai/memory/storage/lancedb_storage.py
Memory updates, encoding plans, schema placeholders, parsing fallbacks, and record touch operations now generate timezone-aware UTC timestamps.
Timezone-aware recency tests
lib/crewai/tests/memory/test_unified_memory.py
Composite score tests now construct fresh and aged memory records with timezone-aware UTC timestamps.

Suggested reviewers: joaomdmoura

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: replacing deprecated naive UTC timestamps with timezone-aware UTC datetimes.
Description check ✅ Passed The description is directly related to the changeset and accurately lists the affected memory files and Python 3.12 compatibility goal.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/crewai/src/crewai/memory/storage/lancedb_storage.py (1)

264-271: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Normalize legacy timestamps to UTC in LanceDB records. \_parse_dt() leaves naive datetime.utcnow().isoformat() values unchanged, so compute_composite_score() and get_scope_info() can raise TypeError when they mix naive and UTC-aware datetimes. Normalize both parsed strings and datetime inputs here, and reuse the same helper in get_scope_info().

🤖 Prompt for 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.

In `@lib/crewai/src/crewai/memory/storage/lancedb_storage.py` around lines 264 -
271, Update _row_to_record’s _parse_dt helper to convert naive datetime inputs
and parsed timestamp strings to UTC-aware datetimes, while preserving existing
timezone information for aware values. Reuse this normalization helper in
get_scope_info() so all timestamp comparisons in compute_composite_score() and
scope handling consistently use UTC-aware datetimes.
🤖 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.

Outside diff comments:
In `@lib/crewai/src/crewai/memory/storage/lancedb_storage.py`:
- Around line 264-271: Update _row_to_record’s _parse_dt helper to convert naive
datetime inputs and parsed timestamp strings to UTC-aware datetimes, while
preserving existing timezone information for aware values. Reuse this
normalization helper in get_scope_info() so all timestamp comparisons in
compute_composite_score() and scope handling consistently use UTC-aware
datetimes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 95a68663-00c3-4daf-939d-04ec76055510

📥 Commits

Reviewing files that changed from the base of the PR and between 4e23bf6 and eefdea3.

📒 Files selected for processing (4)
  • lib/crewai/src/crewai/memory/encoding_flow.py
  • lib/crewai/src/crewai/memory/storage/lancedb_storage.py
  • lib/crewai/src/crewai/memory/types.py
  • lib/crewai/src/crewai/memory/unified_memory.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