You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raise TypeError: can't compare offset-naive and offset-aware datetimes
Code fixes
def is_due(self):
if not self.model.enabled:
# 5 second delay for re-enable.
return schedules.schedstate(False, 5.0)
# START DATE: only run after the `start_time`, if one exists.
if self.model.start_time is not None:
now = self._default_now()
if getattr(settings, 'DJANGO_CELERY_BEAT_TZ_AWARE', True):
now = maybe_make_aware(self._default_now())
if self.model.start_time.tzinfo is None:
if now.tzinfo is not None:
now=now.replace(tzinfo=None)
After adding the code it works fine
if self.model.start_time.tzinfo is None:
if now.tzinfo is not None:
now=now.replace(tzinfo=None)
but save data raise error
MySQL backend does not support timezone-aware datetimes when USE_TZ is False.
to solve this bug, add the following code
def save(self):
# Object may not be synchronized, so only
# change the fields we care about.
obj = type(self.model)._default_manager.get(pk=self.model.pk)
for field in self.save_fields:
setattr(obj, field, getattr(self.model, field))
if obj.start_time and obj.start_time.tzinfo:
obj.start_time=obj.start_time.replace(tzinfo=None)
if obj.last_run_at and obj.last_run_at.tzinfo:
obj.last_run_at=obj.last_run_at.replace(tzinfo=None)
if hasattr(obj,'data_changed') and getattr(obj,'data_changed').tzinfo:
obj.data_changed=obj.data_changed.replace(tzinfo=None)
obj.save()
Detailed information
Please include more detailed information here, such as relevant information about your system setup, things you did to try and debug the problem, log messages, etc.
The text was updated successfully, but these errors were encountered:
Summary:
Include a brief description of the problem here, and fill out the version info below.
Celery Version: 5.4.0
Celery-Beat Version: 2.7.0
Exact steps to reproduce the issue:
Code fixes
After adding the code it works fine
but save data raise error
to solve this bug, add the following code
Detailed information
Please include more detailed information here, such as relevant information about your system setup, things you did to try and debug the problem, log messages, etc.
The text was updated successfully, but these errors were encountered: