From a1d58577954b524fa9e9a53eeda8a6b322c0ac54 Mon Sep 17 00:00:00 2001
From: George Katsikas <giorgakis.katsikas@gmail.com>
Date: Tue, 8 Oct 2024 14:29:17 +0200
Subject: [PATCH] add typehints to profile

fix crash on profile merge
---
 scipost_django/profiles/forms.py  | 10 +++-------
 scipost_django/profiles/models.py | 11 +++++++++++
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/scipost_django/profiles/forms.py b/scipost_django/profiles/forms.py
index a9daade84..daa2f9b57 100644
--- a/scipost_django/profiles/forms.py
+++ b/scipost_django/profiles/forms.py
@@ -194,8 +194,8 @@ class ProfileMergeForm(forms.Form):
         Perform the actual merge: save all data from to-be-deleted profile
         into the one to be kept.
         """
-        profile = self.cleaned_data["to_merge_into"]
-        profile_old = self.cleaned_data["to_merge"]
+        profile: "Profile" = self.cleaned_data["to_merge_into"]
+        profile_old: "Profile" = self.cleaned_data["to_merge"]
 
         # Merge information from old to new Profile.
         if profile.orcid_id is None:
@@ -226,11 +226,7 @@ class ProfileMergeForm(forms.Form):
         profile_old.publicationauthorstable_set.all().update(profile=profile)
 
         # Move all invitations to the "new" profile
-        profile_old.referee_invitations.all().update(
-            profile=profile,
-            referee=getattr(profile, "contributor", None)
-            or getattr(profile_old, "contributor", None),
-        )
+        profile_old.referee_invitations.all().update(referee=profile)
         profile_old.registrationinvitation_set.all().update(profile=profile)
 
         # Move all PotentialFellowships to the "new" profile
diff --git a/scipost_django/profiles/models.py b/scipost_django/profiles/models.py
index b240ea54f..7fd86184d 100644
--- a/scipost_django/profiles/models.py
+++ b/scipost_django/profiles/models.py
@@ -63,9 +63,20 @@ class Profile(models.Model):
     """
 
     if TYPE_CHECKING:
+        from submissions.models.submission import SubmissionAuthorProfile
+        from invitations.models import RegistrationInvitation
+        from colleges.models import FellowshipNomination, PotentialFellowship
+
         id: int
         contributor: Contributor | None
         referee_invitations: "RelatedManager[RefereeInvitation]"
+        emails: "RelatedManager[ProfileEmail]"
+        affiliations: "RelatedManager[Affiliation]"
+        submissionauthorprofile_set: "RelatedManager[SubmissionAuthorProfile]"
+        publicationauthorstable_set: "RelatedManager[PublicationAuthorsTable]"
+        registrationinvitation_set: "RelatedManager[RegistrationInvitation]"
+        potentialfellowship_set: "RelatedManager[PotentialFellowship]"
+        fellowship_nominations: "RelatedManager[FellowshipNomination]"
 
     title = models.CharField(max_length=4, choices=TITLE_CHOICES, default=TITLE_DR)
     first_name = models.CharField(max_length=64)
-- 
GitLab