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

datetime.utcnow and datetime.utcfromtimestamp are deprecated in Python 3.12 #32344

Closed
2 tasks done
tirkarthi opened this issue Jul 4, 2023 · 7 comments · Fixed by #37473
Closed
2 tasks done

datetime.utcnow and datetime.utcfromtimestamp are deprecated in Python 3.12 #32344

tirkarthi opened this issue Jul 4, 2023 · 7 comments · Fixed by #37473
Assignees
Labels
area:core kind:meta High-level information important to the community

Comments

@tirkarthi
Copy link
Contributor

Apache Airflow version

2.6.2

What happened

The usage of datetime.utcnow is deprecated in Python 3.12 and it can be replaced with airflow.utils.timezone.utcnow and a similar method can be introduced for utcfromtimestamp too in timezone module

datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC. (Contributed by Paul Ganssle in gh-103857.)

What you think should happen instead

No response

How to reproduce

./python                     
Python 3.13.0a0 (heads/main:58906213cc, Jul  3 2023, 21:54:53) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.utcnow()
<stdin>:1: DeprecationWarning: datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.now(datetime.UTC).
datetime.datetime(2023, 7, 4, 12, 41, 45, 658447)
>>> datetime.datetime.utcfromtimestamp(10000)
<stdin>:1: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC).
datetime.datetime(1970, 1, 1, 2, 46, 40)

Operating System

Ubuntu

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@tirkarthi tirkarthi added area:core kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Jul 4, 2023
@tirkarthi
Copy link
Contributor Author

I am working on a PR for this and will create it once complete.

@potiuk
Copy link
Member

potiuk commented Jul 4, 2023

Just be warned. We are using pendulum in some places. And in some not. This might have rather undesireable side effects when you replace those deprecated. Not sure how but I know @uranusjr had a document once describing some changes that might be needed to handle the complexity involved and it was not trivial.

@uranusjr
Copy link
Member

uranusjr commented Jul 4, 2023

I talked to Paul Ganssle a while ago and these two specifically have few caveats, you basically need to use the version without utc and make sure to always attach an appropriate timezone. Or since we already use Pendulum we can just use its now(UTC). I’ll take a look at the PR once submitted though.

@tirkarthi
Copy link
Contributor Author

timezone.utcnow that constructs current time without timezone and then uses replace to update the timezone. It is used in many places. There are also places where datetime.utcnow() is used that has no timezone and as per the linked cpython bug this leads to issues where this gets passed to timezone aware functions. My attempt would be to replace them with timezone.utcnow version. See also python/cpython#81669 (comment) for an example

@jscheffl
Copy link
Contributor

jscheffl commented Jul 4, 2023

I would not call it a bug though. It is rather an improvement as Python 3.12 is not officially supported yet. So a PR is appreciated but will be something like a feature to prepare for support Python 3.12++ in future releases.

@potiuk potiuk removed kind:bug This is a clearly a bug needs-triage label for new issues that we didn't triage yet labels Jul 4, 2023
@jscheffl jscheffl added kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet labels Jul 4, 2023
@potiuk
Copy link
Member

potiuk commented Jul 4, 2023

I would not call it a bug though. It is rather an improvement as Python 3.12 is not officially supported yet. So a PR is appreciated but will be something like a feature to prepare for support Python 3.12++ in future releases.

yes

@jscheffl jscheffl removed the needs-triage label for new issues that we didn't triage yet label Jul 4, 2023
@eladkal eladkal added kind:meta High-level information important to the community and removed kind:feature Feature Requests labels Aug 26, 2023
@tirkarthi
Copy link
Contributor Author

Unfortunately, I don't have the bandwidth to proceed with the fix. If someone wants to use my work as base please feel free to check the changes at https://github.com/tirkarthi/airflow/tree/fix-datetime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core kind:meta High-level information important to the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants