-
Notifications
You must be signed in to change notification settings - Fork 429
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
Conversation
django_celery_beat/models.py
Outdated
@@ -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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
This pull request introduces 1 alert when merging 13d403a into be0651f - view on LGTM.com new alerts:
|
can you add small unit test for it? |
@auvipy |
ok please come with it today please |
Done #485 |
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.