From 82a685acb10578fe7fa072927970d41aaea02a1a Mon Sep 17 00:00:00 2001
From: Helge Jung <hej@c3pb.de>
Date: Mon, 25 Dec 2023 19:02:32 +0100
Subject: [PATCH] schedule import: try to preserve the imported speaker's id

---
 src/core/models/schedules.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/core/models/schedules.py b/src/core/models/schedules.py
index 85ff87e28..7eb8738f3 100644
--- a/src/core/models/schedules.py
+++ b/src/core/models/schedules.py
@@ -174,6 +174,12 @@ class ScheduleSource(models.Model):
             'last_name': name_split.pop(),
             'first_name': ' '.join(name_split),
         }
+
+        # set an existing UUID, if possible
+        if mail_guid:
+            user_kwargs['uuid'] = str(mail_guid)
+
+        # create the PlatformUser
         new_user = PlatformUser(**user_kwargs)
         new_user.save()
 
@@ -254,7 +260,7 @@ class ScheduleSource(models.Model):
         except ValueError:
             pass
         try:
-            candidate = item.get('guid')
+            candidate = item.get('uuid') or item.get('guid')
             if item_source_uuid is None and candidate and not isinstance(candidate, int):
                 item_source_uuid = UUID(candidate)
         except ValueError:
@@ -271,7 +277,7 @@ class ScheduleSource(models.Model):
 
         mapping, new_mapping = self.get_or_create_mapping(
             mapping_type=item_type,
-            source_id=item_source_id,
+            source_id=str(item_source_id),
             create_local_object=not item_delete,
             source_uuid=item_source_uuid,
             hints=hints,
-- 
GitLab