Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botocore raises DeprecationWarning: datetime.datetime.utcnow() when running tests with pytests on python 3.12 #3038

Closed
kfrydel opened this issue Oct 16, 2023 · 2 comments
Assignees
Labels
bug This issue is a confirmed bug. duplicate This issue is a duplicate.

Comments

@kfrydel
Copy link

kfrydel commented Oct 16, 2023

Describe the bug

We are switching our project to Python 3.12. Our tests that use botocore started to fail with:

...
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/client.py:535: in _api_call
    return self._make_api_call(operation_name, kwargs)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/client.py:963: in _make_api_call
    http, parsed_response = self._make_request(
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/client.py:986: in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/endpoint.py:119: in make_request
    return self._send_request(request_dict, operation_model)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/endpoint.py:198: in _send_request
    request = self.create_request(request_dict, operation_model)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/endpoint.py:134: in create_request
    self._event_emitter.emit(
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/hooks.py:412: in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/hooks.py:256: in emit
    return self._emit(event_name, kwargs)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/hooks.py:239: in _emit
    response = handler(**kwargs)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/signers.py:105: in handler
    return self.sign(operation_name, request)
/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/signers.py:189: in sign
    auth.add_auth(request)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <botocore.auth.S3SigV4Auth object at 0x7fd6f6bf2a20>, request = <botocore.awsrequest.AWSRequest object at 0x7fd6f6bf2840>

    def add_auth(self, request):
        if self.credentials is None:
            raise NoCredentialsError()
>       datetime_now = datetime.datetime.utcnow()
E       DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

/home/user/.virtualenvs/py-3.12/lib/python3.12/site-packages/botocore/auth.py:419: DeprecationWarning

I know I can add an ignore to pytest.ini but it would be good to avoid ignores.

Expected Behavior

No warning is raised.

Current Behavior

DeprecationWarning is issued

Reproduction Steps

Create a file with valid credentials:

from botocore import session


def test_create_bucket():
    s3 = session.get_session().create_client(
        's3',
        aws_access_key_id='some key id',
        aws_secret_access_key='some access key',
        endpoint_url='some endpoint url',
    )
    s3.create_bucket(Bucket='some-name')

and run pytest for the file:

pytest test_file.py

Possible Solution

Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC) instead of datetime.datetime.utcnow().

Additional Information/Context

No response

SDK version used

1.31.63

Environment details (OS name and version, etc.)

Ubuntu 22.04, Python 3.12

@kfrydel kfrydel added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Oct 16, 2023
@tim-finnigan tim-finnigan self-assigned this Oct 16, 2023
@tim-finnigan tim-finnigan added duplicate This issue is a duplicate. and removed needs-triage This issue or PR still needs to be triaged. labels Oct 16, 2023
@tim-finnigan
Copy link
Contributor

Hi @kfrydel — the team is currently tracking this issue here: boto/boto3#3889. I'm going to resolve this is as a duplicate. Here was the comment that I added on that issue:

...The team is aware of this issue and working on addressing the warnings. These deprecations won't cause impact currently beyond the warnings. The required changes are not fully backwards compatible for existing usage. We'll be prioritizing a more robust fix in an upcoming release.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. duplicate This issue is a duplicate.
Projects
None yet
Development

No branches or pull requests

2 participants