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

fix: update PeriodicTask from entry (#344) #596

Merged
merged 1 commit into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion django_celery_beat/schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,13 @@ def from_entry(cls, name, app=None, **entry):
def _unpack_fields(cls, schedule,
args=None, kwargs=None, relative=None, options=None,
**entry):
entry_schedules = {
model_field: None for _, _, model_field in cls.model_schedules
}
model_schedule, model_field = cls.to_model_schedule(schedule)
entry_schedules[model_field] = model_schedule
entry.update(
{model_field: model_schedule},
entry_schedules,
args=dumps(args or []),
kwargs=dumps(kwargs or {}),
**cls._unpack_options(**options or {})
Expand Down
13 changes: 13 additions & 0 deletions t/unit/test_schedulers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def create_model(self, Model=PeriodicTask, **kwargs):
def create_interval_schedule(self):
return IntervalSchedule.objects.create(every=10, period=DAYS)

def create_crontab_schedule(self):
return CrontabSchedule.objects.create()


@pytest.mark.django_db()
class test_ModelEntry(SchedulerCase):
Expand Down Expand Up @@ -334,6 +337,16 @@ def test_periodic_task_model_disabled_schedule(self):
assert 'celery.backend_cleanup' in sched
assert self.entry_name not in sched

def test_periodic_task_model_schedule_type_change(self):
self.m1.interval = None
self.m1.crontab = self.create_crontab_schedule()
self.m1.save()

self.Scheduler(app=self.app)
self.m1.refresh_from_db()
assert self.m1.interval
assert self.m1.crontab is None


@pytest.mark.django_db()
class test_DatabaseScheduler(SchedulerCase):
Expand Down