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 ClockedSchedule and PeriodicTasks showing UTC time when Time Zone is enabled. #464

Merged
merged 4 commits into from
Dec 17, 2021

Conversation

moreaba
Copy link
Contributor

@moreaba moreaba commented Dec 3, 2021

This contribution fixes 2 serious issues when displaying timing on Django Admin:

1- When time zone is used, celery beat ClockedSchedule model shows two different times which causes discrepancies.
For example, When you enter the django admin > Clocked > list display item, you will find the time is right (w.r.t your TZ), like: Dec. 3, 2021, 6:11 p.m.
However, when you click on this item to open the detailed view it will show the UTC time of the clock you entered reesulting in discrepancies, like: 2021-12-03 16:11:57+00:00

2- When time zone is used, celery beat PeriodicTasks model shows the the name of the task and the datetime of the task in UTC not in the local time zone chosen, which causes great confusion in the periodic tasks.
For example, the PeriodicTasks list will have a task like this: "Send Email: 2021-12-03 16:20:57+00:00" but as a matter of fact this should be 6:20 PM not 4:20 PM as shown in the list, although I have CELERY_ENABLE_UTC = False and CELERY_TIMEZONE = 'Africa/Cairo'

This fix solves both problems and shows the correct time with respect to time zone.

@moreaba moreaba marked this pull request as draft December 3, 2021 16:31
@moreaba moreaba marked this pull request as ready for review December 3, 2021 16:33
@@ -220,7 +221,8 @@ class Meta:
ordering = ['clocked_time']

def __str__(self):
return '{}'.format(self.clocked_time)
return localtime(self.clocked_time).strftime("%d %B %Y %I:%M %p")
Copy link
Member

Choose a reason for hiding this comment

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

can unit test added for this change?

Copy link

Choose a reason for hiding this comment

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

I think return '{}'.format(make_aware(self.clocked_time)) is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes @lvelvee I believe so.
I have done another commit with this change after fetching the new base code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you

@lgtm-com
Copy link

lgtm-com bot commented Dec 15, 2021

This pull request introduces 1 alert when merging 13d403a into be0651f - view on LGTM.com

new alerts:

  • 1 for Unused import

@moreaba moreaba requested a review from auvipy December 15, 2021 16:13
@auvipy
Copy link
Member

auvipy commented Dec 15, 2021

can you add small unit test for it?

@auvipy auvipy merged commit eb2af29 into celery:master Dec 17, 2021
@moreaba
Copy link
Contributor Author

moreaba commented Dec 17, 2021

@auvipy
Yes sure
I have written it.
I will commit it today.

@auvipy
Copy link
Member

auvipy commented Dec 17, 2021

ok please come with it today please

@moreaba
Copy link
Contributor Author

moreaba commented Dec 17, 2021

ok please come with it today please

Done #485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants