Skip to content

Commit

Permalink
fix: update PeriodicTask from entry (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
petr.prikryl authored and auvipy committed Oct 18, 2022
1 parent 51c5bd8 commit 10539af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 10539af

Please sign in to comment.