Skip to content

chore: replace deprecated datetime.utcnow() with datetime.now(timezone.utc) across codebase#16

Open
devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
devin/1772849972-replace-deprecated-utcnow-calls
Open

chore: replace deprecated datetime.utcnow() with datetime.now(timezone.utc) across codebase#16
devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
devin/1772849972-replace-deprecated-utcnow-calls

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 7, 2026

chore: replace deprecated datetime.utcnow() calls with datetime.now(timezone.utc)

Summary

Replaces all datetime.utcnow() call sites in main.py (4 occurrences) and scrapers/base.py (1 occurrence) with the modern datetime.now(timezone.utc). datetime.utcnow() was deprecated in Python 3.12, and this repo runs on Python 3.12.8 where it emits DeprecationWarning. Also removes a now-redundant from datetime import timezone local import inside seed_demo_data() since timezone is now imported at module level.

Updates since last revision

  • Resolved merge conflict with master caused by PR chore: remove unused Optional import from main.py #11 (removal of unused Optional import). The Optional import line was dropped (per master) while retaining the new timezone import from this branch. No functional changes.

Review & Testing Checklist for Human

  • Naive vs. aware datetime mismatch (HIGH RISK): datetime.now(timezone.utc) returns a timezone-aware datetime, whereas the old datetime.utcnow() returned a naive datetime. The FXRate.scraped_at and MidMarketRate.scraped_at database columns store naive datetimes. Verify that comparing timezone-aware since values against naive scraped_at values in print_report() and print_all_pairs_report() does not raise TypeError or produce incorrect query results in SQLAlchemy/SQLite.
  • ScraperResult.scraped_at is now timezone-aware: ScraperResult.scraped_at is set to datetime.now(timezone.utc) (aware) and later assigned to FXRate.scraped_at (a naive DateTime column) via save_results(). Confirm SQLAlchemy handles this gracefully with SQLite—it may silently strip tzinfo, but this should be verified.
  • Coordinate with PR chore: replace deprecated datetime.utcnow Column defaults with datetime.now(timezone.utc) in database/models.py #15: PR chore: replace deprecated datetime.utcnow Column defaults with datetime.now(timezone.utc) in database/models.py #15 separately updates the Column defaults in database/models.py using .replace(tzinfo=None) to stay naive. If both PRs merge, ensure consistency—either go fully timezone-aware or stay naive everywhere.
  • Test plan: Run python main.py --demo then python main.py --report and confirm no TypeError on datetime comparisons. Inspect fx_fees.db to check scraped_at values are reasonable UTC timestamps.

Notes

…e.utc) across codebase

Co-Authored-By: bot_apk <apk@cognition.ai>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…alls

Co-Authored-By: bot_apk <apk@cognition.ai>
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.

0 participants