Skip to content

fix: Resolve Python 3.12 datetime.utcnow() DeprecationWarning#10490

Draft
kdaily wants to merge 4 commits into
v2from
kdaily-utcnow-deprecation-fix-v2
Draft

fix: Resolve Python 3.12 datetime.utcnow() DeprecationWarning#10490
kdaily wants to merge 4 commits into
v2from
kdaily-utcnow-deprecation-fix-v2

Conversation

@kdaily

@kdaily kdaily commented Jul 16, 2026

Copy link
Copy Markdown
Member

Issue #, if available:

boto/botocore#3239

Description of changes:

Port of botocore PR boto/botocore#3239.

Replace datetime.datetime.utcnow() with datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) to resolve the Python 3.12 DeprecationWarning while ensuring datetime instances remain timezone-unaware for backward compatibility.

Update test mocks from .utcnow to .now to match the new code paths.

Upstream: boto/botocore@57086ff
Upstream PR: boto/botocore#3239

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

kdaily added 4 commits July 15, 2026 18:50
Port of botocore commit 57086ff (PR #3239) by @kurtmckee.

Replace datetime.datetime.utcnow() with
datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) to
resolve the Python 3.12 DeprecationWarning while ensuring datetime
instances remain timezone-unaware for backward compatibility.

Update test mocks from .utcnow to .now to match the new code paths.

Upstream: boto/botocore@57086ff
Upstream PR: boto/botocore#3239
Port of botocore commit 7ebb8b8 (PR #3533) by @nateprewitt.

Introduce get_current_datetime() utility in botocore.compat to
centralize the datetime.now(timezone.utc) pattern. This makes it
easier to mock in tests and provides a single point of maintenance
for timezone-aware datetime retrieval.

The CRT auth module uses get_current_datetime(remove_tzinfo=False)
since the CRT library expects timezone-aware datetime objects.

Retarget test_signers mock from botocore.signers.datetime to
botocore.compat.datetime since get_current_datetime() now lives
in botocore.compat.

Upstream: boto/botocore@7ebb8b8
Upstream PR: boto/botocore#3533
Port of botocore commit bbed2c0 (PR #3533) by @nateprewitt.

Add tzinfo=datetime.timezone.utc to test datetime fixtures to match
the real behavior of get_current_datetime() which internally calls
datetime.datetime.now(datetime.timezone.utc). This ensures mocked
return values are consistent with production code behavior, which is
important for the CRT auth path that uses remove_tzinfo=False.

Upstream: boto/botocore@bbed2c0
Upstream PR: boto/botocore#3533
Replace datetime.utcnow() with datetime.now(timezone.utc) in awscli
customization modules:

- awscli/customizations/eks/get_token.py
- awscli/customizations/logs/tail.py
- awscli/customizations/ec2/bundleinstance.py
- awscli/customizations/cloudformation/deployer.py
- awscli/customizations/cloudtrail/validation.py
- awscli/customizations/codecommit.py
- awscli/customizations/codedeploy/push.py
- awscli/customizations/datapipeline/__init__.py

Update test mocks from .utcnow to .now across all affected test files.
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