Skip to content

Commit

Permalink
Fix IntegrityError when creating periodic tasks
Browse files Browse the repository at this point in the history
Change PeriodicTask.objects.get_or_create() to PeriodicTask.objects.update_or_create().

This change prevents a potential IntegrityError when creating a periodic task due to duplicate primary key. By using update_or_create, if the record already exists, it will be updated instead of attempting to insert a new record with the same primary key, ensuring the process completes without error.
  • Loading branch information
Guanchishan authored Oct 11, 2024
1 parent 13381b9 commit 6143aa6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bookwyrm/views/admin/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def post(self, request):
schedule, _ = IntervalSchedule.objects.get_or_create(
**schedule_form.cleaned_data
)
PeriodicTask.objects.get_or_create(
PeriodicTask.objects.update_or_create(
interval=schedule,
name="check-for-updates",
task="bookwyrm.models.site.check_for_updates_task",
Expand Down

0 comments on commit 6143aa6

Please sign in to comment.