django-celery-beat
django-celery-beat copied to clipboard
Cannot programmatically set a schedule
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:
- Create a ModelAdmin where crontab is read-only
- Create a ModelForm and override
clean()
to programmatically set the crontab - 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.
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. :(
you can come with a PR with failing tests