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

Use timezone.utc instead of datetime.UTC for backwards compatibility #303

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

rcritten
Copy link
Collaborator

We switched to datetime.UTC because datetime.utcnow() was deprecated. This is only available in python 3.11+. Use datetime.timezone.utc instead which is available from python 3.2+

Fixes: #302

@flo-renaud
Copy link
Contributor

Hi @rcritten
thanks for the patch, works well for me. I tested on fedora 38 with python 3.11 and on RHEL 9.3 with python 3.9.

The patch is missing an update for tests/test_ipa_certfile_expiration.py though, which contains a few occurrences of UTC:

# pytest
============================= test session starts ==============================
platform linux -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /root/freeipa-healthcheck
collected 188 items / 1 error                                                  

==================================== ERRORS ====================================
____________ ERROR collecting tests/test_ipa_certfile_expiration.py ____________
ImportError while importing test module '/root/freeipa-healthcheck/tests/test_ipa_certfile_expiration.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_ipa_certfile_expiration.py:18: in <module>
    from datetime import datetime, timedelta, UTC
E   ImportError: cannot import name 'UTC' from 'datetime' (/usr/lib64/python3.9/datetime.py)
=========================== short test summary info ============================
ERROR tests/test_ipa_certfile_expiration.py
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.60s ===============================

@rcritten
Copy link
Collaborator Author

Hi @rcritten thanks for the patch, works well for me. I tested on fedora 38 with python 3.11 and on RHEL 9.3 with python 3.9.

The patch is missing an update for tests/test_ipa_certfile_expiration.py though, which contains a few occurrences of UTC:

Can't believe I missed those. Fixed now.

Copy link
Contributor

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rcritten
thanks for the update, works for me. Tested on RHEL 9.3 with python3-3.9.18-1.el9_3.x86_64:

# pytest tests/test_ipa_certfile_expiration.py 
======================================================================================= test session starts ========================================================================================
platform linux -- Python 3.9.18, pytest-7.4.2, pluggy-1.3.0
rootdir: /root/freeipa-healthcheck
collected 3 items                                                                                                                                                                                  

tests/test_ipa_certfile_expiration.py ...                                                                                                                                                    [100%]

======================================================================================== 3 passed in 0.43s =========================================================================================

The CI issue (container(38)) should be fixed with PR #306.

@flo-renaud flo-renaud added the ack label Oct 16, 2023
We switched to datetime.UTC because datetime.utcnow() was deprecated.
This is only available in python 3.11+. Use datetime.timezone.utc
instead which is available from python 3.2+

Fixes: freeipa#302

Signed-off-by: Rob Crittenden <[email protected]>
@rcritten rcritten merged commit fd0b2ce into freeipa:master Oct 16, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

module 'datetime' has no attribute 'UTC'
2 participants