Skip to content

Replace deprecated datetime.utcnow() with datetime.now(timezone.utc) - #340

Draft
sidewinderzz wants to merge 1 commit into
NabuCasa:masterfrom
sidewinderzz:fix-utcnow-deprecation
Draft

sidewinderzz wants to merge 1 commit into
NabuCasa:masterfrom
sidewinderzz:fix-utcnow-deprecation

Conversation

@sidewinderzz

Copy link
Copy Markdown

Summary

datetime.datetime.utcnow() has been deprecated since Python 3.12 and emits a DeprecationWarning on every SRP login. This switches the two call sites in aws_srp.py (process_challenge, process_device_challenge) and one in tests.py to datetime.now(timezone.utc), ahead of its eventual removal.

No behavior change

The Cognito timestamp strings are byte-identical: both paths only read weekday/month/day/time/year, which match for the naive and aware values (verified under freezegun, including single-digit days).

Testing (Python 3.14.5)

  • pytest tests.py: 17 passed with -W error for the utcnow deprecation (before this change: 1 failed on it)
  • black / flake8 / pylint (10.00/10) clean

🤖 Generated with Claude Code

datetime.datetime.utcnow() has been deprecated since Python 3.12 and
emits a DeprecationWarning on every SRP authentication. Switch the two
call sites in aws_srp.py (and the one in tests.py) to the recommended
timezone-aware datetime.now(timezone.utc).

The formatted Cognito timestamps are unchanged: both helpers only read
weekday/month/day/time/year fields, which are identical for the naive
and aware values.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@af001

af001 commented Sep 24, 2026

Copy link
Copy Markdown

This one would be good to add. Also docs could be updated. I've been on 3.13 without issues.

This branch has not been deployed

No deployments
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.

2 participants