From 6143aa66e3f1cafa236b6efa73c86d7c6c840ab0 Mon Sep 17 00:00:00 2001 From: Davidzdh <30859354+Guanchishan@users.noreply.github.com> Date: Fri, 11 Oct 2024 20:28:27 +0900 Subject: [PATCH] Fix IntegrityError when creating periodic tasks 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. --- bookwyrm/views/admin/dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/admin/dashboard.py b/bookwyrm/views/admin/dashboard.py index 87af434c5..2bfd272e7 100644 --- a/bookwyrm/views/admin/dashboard.py +++ b/bookwyrm/views/admin/dashboard.py @@ -83,7 +83,7 @@ class Dashboard(View): 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",