fix: Resolve Python 3.12 datetime.utcnow() DeprecationWarning#10490
Draft
kdaily wants to merge 4 commits into
Draft
fix: Resolve Python 3.12 datetime.utcnow() DeprecationWarning#10490kdaily wants to merge 4 commits into
kdaily wants to merge 4 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
boto/botocore#3239
Description of changes:
Port of botocore PR boto/botocore#3239.
Replace
datetime.datetime.utcnow()withdatetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)to resolve the Python 3.12DeprecationWarningwhile ensuringdatetimeinstances remain timezone-unaware for backward compatibility.Update test mocks from
.utcnowto.nowto 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.