Skip to content

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

Merged
auvipy merged 2 commits intocelery:mainfrom
cclauss:patch-1
Dec 19, 2023
Merged

Fix DeprecationWarning: datetime.datetime.utcnow()#8726
auvipy merged 2 commits intocelery:mainfrom
cclauss:patch-1

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

@codecov
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

@cclauss cclauss closed this Dec 14, 2023
@cclauss cclauss reopened this Dec 14, 2023
@cclauss cclauss marked this pull request as draft December 14, 2023 10:49
> 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
@Nusnus
Copy link
Member

Nusnus commented Dec 18, 2023

Restarting CI, unrelated error

@auvipy auvipy merged commit 7a27725 into celery:main Dec 19, 2023
@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 cclauss deleted the patch-1 branch December 19, 2023 20:42
@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.

3 participants