Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 5.2.9 on 2025-12-09 09:48

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("django_celery_beat", "0019_alter_periodictasks_options"),
]

operations = [
migrations.AlterField(
model_name="clockedschedule",
name="clocked_time",
field=models.DateTimeField(
help_text="Run the task at clocked time",
unique=True,
verbose_name="Clock Time",
),
),
migrations.AddConstraint(
model_name="crontabschedule",
constraint=models.UniqueConstraint(
fields=(
"minute",
"hour",
"day_of_month",
"month_of_year",
"day_of_week",
"timezone",
),
name="unique_crontab",
),
),
migrations.AddConstraint(
model_name="intervalschedule",
constraint=models.UniqueConstraint(
fields=("every", "period"), name="unique_interval"
),
),
]
21 changes: 19 additions & 2 deletions django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class Meta:
verbose_name = _('interval')
verbose_name_plural = _('intervals')
ordering = ['period', 'every']
constraints = [
models.UniqueConstraint(fields=["every", "period"], name="unique_interval")
]
Comment on lines +176 to +178
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique constraints added by this PR will prevent the creation of duplicate schedules, but the existing test _test_duplicate_schedules in t/unit/test_models.py expects to be able to create duplicates (line 77 creates a second instance with the same kwargs, and line 78 expects 2 instances to exist). These tests will now fail with IntegrityError when trying to create the second duplicate instance. The tests need to be updated to either:

  1. Test that duplicates are prevented (expect IntegrityError)
  2. Use different kwargs for the second instance
  3. Test that from_schedule properly handles uniqueness with get_or_create

Copilot uses AI. Check for mistakes.

@property
def schedule(self):
Expand Down Expand Up @@ -214,8 +217,9 @@ class ClockedSchedule(models.Model):
"""clocked schedule."""

clocked_time = models.DateTimeField(
verbose_name=_('Clock Time'),
help_text=_('Run the task at clocked time'),
verbose_name=_("Clock Time"),
help_text=_("Run the task at clocked time"),
unique=True,
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique constraint on clocked_time will prevent the creation of duplicate schedules, but the existing test test_duplicate_schedules in ClockedScheduleTestCase (t/unit/test_models.py, line 148-150) expects to be able to create duplicates. This test will now fail with IntegrityError. The test needs to be updated to verify that the unique constraint works correctly.

Copilot uses AI. Check for mistakes.
)

class Meta:
Expand Down Expand Up @@ -314,6 +318,19 @@ class Meta:
verbose_name_plural = _('crontabs')
ordering = ['month_of_year', 'day_of_month',
'day_of_week', 'hour', 'minute', 'timezone']
constraints = [
models.UniqueConstraint(
fields=[
"minute",
"hour",
"day_of_month",
"month_of_year",
"day_of_week",
"timezone",
],
name="unique_crontab",
)
]
Comment on lines +321 to +333
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unique constraint on CrontabSchedule will prevent the creation of duplicate schedules, but the existing test test_duplicate_schedules in CrontabScheduleTestCase (t/unit/test_models.py, line 99-109) expects to be able to create duplicates. This test will now fail with IntegrityError. The test needs to be updated to verify that the unique constraint works correctly.

Copilot uses AI. Check for mistakes.

@property
def human_readable(self):
Expand Down
Loading