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

Fix DeprecationWarning: datetime.datetime.utcnow() #8726

Merged
merged 2 commits into from Dec 19, 2023
Merged

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Dec 14, 2023

Description

Fix DeprecationWarning: datetime.datetime.utcnow() on Python 3.12

lib/python3.12/site-packages/celery/app/base.py:940: 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).
    now_in_utc = to_utc(datetime.utcnow())

https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d1350f9) 87.27% compared to head (a3b290d) 87.24%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8726      +/-   ##
==========================================
- Coverage   87.27%   87.24%   -0.04%     
==========================================
  Files         148      148              
  Lines       18636    18637       +1     
  Branches     3199     3199              
==========================================
- Hits        16265    16260       -5     
- Misses       2078     2080       +2     
- Partials      293      297       +4     
Flag Coverage Δ
unittests 87.21% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cclauss cclauss changed the title app/base.py: Fix DeprecationWarning: datetime.datetime.utcnow() Fix DeprecationWarning: datetime.datetime.utcnow() Dec 14, 2023
@auvipy auvipy self-requested a review December 14, 2023 10:24
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

you can make it draft before the builds are passing

> lib/python3.12/site-packages/celery/app/base.py:940: 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).
    now_in_utc = to_utc(datetime.utcnow())
@cclauss cclauss marked this pull request as ready for review December 14, 2023 14:39
@cclauss cclauss requested a review from auvipy December 14, 2023 14:39
@Nusnus Nusnus self-requested a review December 14, 2023 21:00
@thedrow
Copy link
Member

thedrow commented Dec 18, 2023

Please rebase to resolve the conflicts.

@Nusnus
Copy link
Member

Nusnus commented Dec 18, 2023

Restarting CI, unrelated error

@auvipy auvipy merged commit 7a27725 into celery:main Dec 19, 2023
32 of 33 checks passed
@auvipy auvipy added this to the 5.4 milestone Dec 19, 2023
@auvipy
Copy link
Member

auvipy commented Dec 19, 2023

great job! thanks a lot

@cclauss
Copy link
Contributor Author

cclauss commented Dec 19, 2023

There is more utcnow() to deal with but these instance are harder to figure out...

cclauss added a commit to cclauss/celery that referenced this pull request Dec 19, 2023
A continuation of celery#8726
* celery#8726

% `python3.12`
```
>>> from datetime import datetime, timezone
>>> datetime.now(timezone.utc).isoformat()[:-9], datetime.utcnow().isoformat()[:-3]
<stdin>:1: 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).
('2023-12-19T21:15:19.935', '2023-12-19T21:15:19.935')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants