django-celery-beat icon indicating copy to clipboard operation
django-celery-beat copied to clipboard

Validation error when changing the scheduletype in beat settings

Open Sult opened this issue 4 years ago • 8 comments

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:

  1. setup a beat task with a crontab() schedule
  2. start celery beat and stop it again
  3. change the task to datetime.timedelta(seconds=10)
  4. 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

Sult avatar May 28 '20 12:05 Sult

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

Sult avatar Jun 10 '20 15:06 Sult

Also noticed the first issue you stated when I changed 'schedule': crontab(minute=0, hour=0) to 'schedule': 5.0

sudomann avatar Jun 23 '20 02:06 sudomann

Also facing the same ValidationError

anuj9196 avatar Sep 08 '20 01:09 anuj9196

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!

cecases avatar Feb 02 '21 16:02 cecases

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.

auvipy avatar Feb 12 '21 05:02 auvipy

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.

wrvdklooster avatar Mar 12 '21 21:03 wrvdklooster

Any Update, facing the same ValidationError

bhargava-kush avatar Dec 23 '21 07:12 bhargava-kush

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

auvipy avatar Dec 23 '21 07:12 auvipy

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.

petrprikryl avatar Oct 07 '22 11:10 petrprikryl

can you come with a prospective solution?

auvipy avatar Oct 13 '22 13:10 auvipy