django-celery-beat
django-celery-beat copied to clipboard
Validation error when changing the scheduletype in beat settings
Summary:
Whenever you change the schedule type of an existing periodic task and restart, the task will fail validation and raises an error: django.core.exceptions.ValidationError: {'interval': ['Only one of clocked, interval, crontab, or solar must be set'], 'crontab': ['Only one of clocked, interval, crontab, or solar must be set']}
- Celery Version: 4.4.2
- Celery-Beat Version: 2.0.0
Exact steps to reproduce the issue:
- setup a beat task with a crontab() schedule
- start celery beat and stop it again
- change the task to datetime.timedelta(seconds=10)
- start beat again
I have inspected the error and it looks like that the scheduled object now has both an interval and a cron that is set. Haven't had time to look at the sourcecode yet,but i expect that the cleaning isn't behaving as it should when the schedule object already exists in the database but has changed from settings
Also now found that when removing an existing beat task from its settings, it wont clear its tasks as well, so it ends up trying to run a task that no longer exists
Also noticed the first issue you stated when I changed
'schedule': crontab(minute=0, hour=0)
to
'schedule': 5.0
Also facing the same ValidationError
If you are using django as backend framework, update your django-celery-beat to 2.2.0, the latest version. https://github.com/celery/django-celery-beat
Then you can edit Periodic Task from Admin deleting the old task, you will see this message on your terminal: "DatabaseScheduler: Schedule changed", try it again, it will works!
If you are using django as backend framework, update your django-celery-beat to 2.2.0, the latest version. https://github.com/celery/django-celery-beat
Then you can edit Periodic Task from Admin deleting the old task, you will see this message on your terminal: "DatabaseScheduler: Schedule changed", try it again, it will works!
closing as per this suggestion.
We set the schedules from code. Making changes from Django admin if we change something is not really an option. We would need to make manual changes on multiple servers.
Any Update, facing the same ValidationError
Any Update, facing the same ValidationError
please provide more concrete info of your problem. and you can always check the code in github and share your thoughts on existing problem
Problem is here: https://github.com/celery/django-celery-beat/blob/5a72e0a1911a7fef1fb725c91d10a61ca1e0e83f/django_celery_beat/schedulers.py#L174-L191
Because _unpack_fields
only creates uncomplete desired state of entry
(PeriodicTask
). And do not unset stale value of interval / crontab / etc. which is in DB. So update will try to add new schedule type into existing PeriodicTask and it fails due unique check. Solution could be to set all other schedule FKs to None.
It only occurs when you switch schedule
type of periodic task in beat_schedule
. And then it happens while beat schedule sync.
can you come with a prospective solution?