From 6b9a973b634baf0e2ead730a3957d16c5a14543f Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Thu, 4 Apr 2024 11:18:28 -0400
Subject: [PATCH] =?UTF-8?q?fix:=20don=E2=80=99t=20use=20bulk=5Fcreate=20an?=
 =?UTF-8?q?d=20don=E2=80=99t=20ignore=20conflicts?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 program/management/commands/addtimeslots.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/program/management/commands/addtimeslots.py b/program/management/commands/addtimeslots.py
index 091e3d72..5fda8008 100644
--- a/program/management/commands/addtimeslots.py
+++ b/program/management/commands/addtimeslots.py
@@ -3,6 +3,7 @@ from datetime import datetime
 from dateutil.rrule import rrule
 
 from django.core.management import BaseCommand
+from django.db import IntegrityError
 from django.utils.timezone import make_aware
 from program.models import RRule, Schedule, TimeSlot
 
@@ -34,6 +35,8 @@ class Command(BaseCommand):
         for schedule in (
             Schedule.objects.exclude(rrule=once).filter(last_date=None).order_by("show__name")
         ):
+            added = 0
+            skipped = 0
             last_timeslot = schedule.timeslots.last()
 
             # add timeslots to the schedules with no timeslot this year
@@ -65,8 +68,16 @@ class Command(BaseCommand):
                         )
                     )
                 else:
-                    TimeSlot.objects.bulk_create(timeslots, ignore_conflicts=True)
+                    for timeslot in timeslots:
+                        try:
+                            timeslot.save()
+                        except IntegrityError:
+                            skipped += 1
+                        else:
+                            added += 1
 
                     self.stdout.write(
-                        self.style.SUCCESS(f"added {str(len(timeslots))} timeslots to {schedule}")
+                        self.style.SUCCESS(
+                            f"added {str(added)} timeslots to {schedule}, skipped {str(skipped)}"
+                        )
                     )
-- 
GitLab