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

Validation error when changing the scheduletype in beat settings #344

Closed
Sult opened this issue May 28, 2020 · 10 comments
Closed

Validation error when changing the scheduletype in beat settings #344

Sult opened this issue May 28, 2020 · 10 comments
Labels

Comments

@Sult
Copy link

Sult commented May 28, 2020

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
Copy link
Author

Sult commented Jun 10, 2020

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

@sudomann
Copy link

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

@anuj9196
Copy link

anuj9196 commented Sep 8, 2020

Also facing the same ValidationError

@cecases
Copy link

cecases commented Feb 2, 2021

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!

@auvipy
Copy link
Member

auvipy commented Feb 12, 2021

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.

@wrvdklooster
Copy link

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.

@auvipy auvipy reopened this Mar 13, 2021
@bhargava-kush
Copy link

Any Update, facing the same ValidationError

@auvipy
Copy link
Member

auvipy commented Dec 23, 2021

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

@petrprikryl
Copy link

Problem is here:

@classmethod
def from_entry(cls, name, app=None, **entry):
return cls(PeriodicTask._default_manager.update_or_create(
name=name, defaults=cls._unpack_fields(**entry),
), app=app)
@classmethod
def _unpack_fields(cls, schedule,
args=None, kwargs=None, relative=None, options=None,
**entry):
model_schedule, model_field = cls.to_model_schedule(schedule)
entry.update(
{model_field: model_schedule},
args=dumps(args or []),
kwargs=dumps(kwargs or {}),
**cls._unpack_options(**options or {})
)
return entry

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.

@auvipy
Copy link
Member

auvipy commented Oct 13, 2022

can you come with a prospective solution?

petrprikryl pushed a commit to petrprikryl/django-celery-beat that referenced this issue Oct 17, 2022
petrprikryl pushed a commit to petrprikryl/django-celery-beat that referenced this issue Oct 17, 2022
petrprikryl pushed a commit to petrprikryl/django-celery-beat that referenced this issue Oct 17, 2022
@auvipy auvipy added bug and removed question labels Oct 18, 2022
@auvipy auvipy closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants