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.
This commit is contained in:
Davidzdh 2024-10-11 20:28:27 +09:00 committed by GitHub
parent 13381b9b4d
commit 6143aa66e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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",