[v2] Port/Update usage of datetime.utcnow for DeprecationWarnings#10488
Closed
kdaily wants to merge 5 commits into
Closed
[v2] Port/Update usage of datetime.utcnow for DeprecationWarnings#10488kdaily wants to merge 5 commits into
kdaily wants to merge 5 commits into
Conversation
Port of botocore commit b0015b7 (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@b0015b7 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. 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
Follow-up to the botocore utcnow deprecation port. The presign command test was still mocking datetime.datetime.utcnow instead of .now, causing 6 test failures. Upstream: boto/botocore@b0015b7 Upstream PR: boto/botocore#3239
Replace datetime.utcnow() with datetime.now(timezone.utc) in awscli customization modules that were not covered by the botocore port: - awscli/customizations/eks/get_token.py - awscli/customizations/logs/tail.py (via _utcnow helper) - awscli/customizations/ec2/bundleinstance.py Update test mocks from .utcnow to .now across all affected test files: - tests/functional/botocore/test_s3express.py - tests/functional/eks/test_get_token.py - tests/functional/logs/test_tail.py - tests/functional/dsql/test_generate_db_auth_token.py - tests/functional/rds/test_generate_db_auth_token.py - tests/functional/ec2instanceconnect/test_opentunnel.py - tests/functional/ec2/test_bundle_instance.py
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:
N/A - Port of upstream botocore fixes for Python 3.12+ compatibility.
Description of changes:
Python 3.12 deprecated
datetime.datetime.utcnow(). This PR ports the upstream botocore fix and applies the same pattern to awscli customization modules.From PR boto/botocore#3239:
b0015b7: Replacedatetime.datetime.utcnow()withdatetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None)in botocore auth/signing code. Update test mocks from.utcnowto.now`.From boto/botocore#3533:
7ebb8b8: Introduceget_current_datetime()utility inbotocore.compatto centralize the pattern. CRT auth usesget_current_datetime(remove_tzinfo=False)since CRT expects timezone-aware datetimes.bbed2c0: Addtzinfo=datetime.timezone.utcto test datetime fixtures to match production behavior.Additionally:
.utcnowto.nowintest_presign_command.py.datetime.utcnow()ineks/get_token.py,logs/tail.py, andec2/bundleinstance.py. Update test mocks across 7 functional test files.Upstream references:
Resolve Python 3.12
.utcnow()DeprecationWarningboto/botocore#3239Add centralized datetime management boto/botocore#3533
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.