Skip to content

Commit aea739c

Browse files
wes-otffrjo
andauthored
Add missing migration for Partners & AssignedReviewers (#4804)
Related to #4790. I missed an edge case where an `AssignedReviewer` was also a Partner, in which the migrations would fail as the `type` attribute is protected in the model. This moves all types of partner to reviewer. --------- Co-authored-by: Fredrik Jonsson <frjo@xdeb.org>
1 parent 4b42119 commit aea739c

1 file changed

Lines changed: 30 additions & 5 deletions

File tree

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
# Generated by Django 5.2.12 on 2026-03-26 19:48
22

33
from django.db import migrations
4-
from django.contrib.auth.models import Group
54

65

7-
def migrate_partners_to_coapplicants(apps, schema_editor):
6+
# An edge case that won't apply to most systems
7+
def assigned_review_migrate_from_partners(apps, schema_editor):
88
PARTNER_GROUP_NAME = "Partner"
9+
REVIEWER_GROUP_NAME = "Reviewer"
910

10-
if Group.objects.filter(name=PARTNER_GROUP_NAME).exists():
11-
Group.objects.get(name=PARTNER_GROUP_NAME).delete()
11+
Group = apps.get_model("auth", "Group")
12+
AssignedReviewers = apps.get_model("funds", "AssignedReviewers")
13+
14+
try:
15+
reviewer_id = Group.objects.get(name=REVIEWER_GROUP_NAME).id
16+
except Group.DoesNotExist:
17+
return
18+
19+
if id_qs := Group.objects.filter(name=PARTNER_GROUP_NAME).values_list(
20+
"id", flat=True
21+
):
22+
AssignedReviewers.objects.filter(type_id=id_qs.first()).update(
23+
type_id=reviewer_id
24+
)
25+
26+
27+
def delete_partner_group(apps, schema_editor):
28+
PARTNER_GROUP_NAME = "Partner"
29+
30+
Group = apps.get_model("auth", "Group")
31+
Group.objects.filter(name=PARTNER_GROUP_NAME).delete()
1232

1333

1434
class Migration(migrations.Migration):
@@ -17,4 +37,9 @@ class Migration(migrations.Migration):
1737
("funds", "0133_remove_applicationsubmission_partners"),
1838
]
1939

20-
operations = [migrations.RunPython(migrate_partners_to_coapplicants)]
40+
operations = [
41+
migrations.RunPython(
42+
assigned_review_migrate_from_partners, migrations.RunPython.noop
43+
),
44+
migrations.RunPython(delete_partner_group, migrations.RunPython.noop),
45+
]

0 commit comments

Comments
 (0)