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

Cannot programmatically set a schedule

Open paxw-panevo opened this issue 2 years ago • 2 comments

Summary:

A schedule cannot be programmatically set without including the schedule in the form and not marking it as read-only. I have to include the crontab (for example) field and not mark it as a read-only although in the backend, the crontab field is completely ignored and set programmatically. This is not good UX,

Ideally, the crontab field is either marked as read-only or completely not displayed on the form. The user still is able to create a task successfully since the crontab field is programmatically set in the backend.

  • Celery Version: 5.2.7
  • Celery-Beat Version: 2.3.0

Exact steps to reproduce the issue:

  1. Create a ModelAdmin where crontab is read-only
  2. Create a ModelForm and override clean() to programmatically set the crontab
  3. In the django-admin UI, create a task

Expected: The user is able to create a task with a crontab programmatically set by the backend. Actual: The user receives an error One of clocked, interval, crontab, or solar must be set.'

Detailed information and proposed change

django excludes fields that are not on the form or read-only fields when validating uniqueness of model instances, https://github.com/django/django/blob/d44ee518c4c110af25bebdbedbbf9fba04d197aa/django/forms/models.py#L380

but django_celery_beat checks that a schedule must exist in the instance during validate_unique() https://github.com/celery/django-celery-beat/blob/975f8ea2a9d0ff4f2809a3c34e43ad3a848f148d/django_celery_beat/models.py#L550-L574

A potential solution to this issue then is to remove the validation of a schedule existing in validate_unique() and move it to a more appropriate method like clean() -- I don't think checking a schedule's existence is relevant to whether the task is unique? If this sounds reasonable, I can create a PR.

paxw-panevo avatar Dec 14 '22 17:12 paxw-panevo

Hi, my friend, have you solved this problem? Is this feedback a problem of celery itself? I've looked for many ways, but I can't fix it. :(

cfvphxzx762 avatar Jan 06 '23 09:01 cfvphxzx762

you can come with a PR with failing tests

auvipy avatar Jan 06 '23 10:01 auvipy