From af86f3c8fb7adb26723301ab4023a19cf1de3378 Mon Sep 17 00:00:00 2001 From: Kelvin Muchiri Date: Mon, 26 Aug 2024 20:21:21 +0300 Subject: [PATCH 1/2] fix argument of type 'ProjectUserObjectPermission' is not iterable fix exception thrown when running migration --- .../0023_populate_project_entity_list_perm.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py b/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py index 14d695d281..998f32372e 100644 --- a/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py +++ b/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py @@ -15,11 +15,11 @@ def add_project_entitylist_perm(apps, schema_editor): """Assign `add_project_entitylist` permission to existing Owners, Managers""" Project = apps.get_model("logger", "Project") content_type = ContentType.objects.get_for_model(Project) - perm = "add_project_entitylist" + perm_str = "add_project_entitylist" with use_master: _, created = Permission.objects.get_or_create( - codename=perm, + codename=perm_str, content_type=content_type, defaults={ "name": "Can add entitylist to project", @@ -27,7 +27,7 @@ def add_project_entitylist_perm(apps, schema_editor): ) if created: - print(f"Permission {perm} created because it does not exist") + print(f"Permission {perm_str} created because it does not exist") project_qs = Project.objects.filter(deleted_at__isnull=True) eta = project_qs.count() @@ -42,13 +42,13 @@ def add_project_entitylist_perm(apps, schema_editor): permission__codename="add_project" ) - for perm in project_user_obj_perm_qs.iterator(chunk_size=100): - user = User.objects.get(id=perm.user_id) - assign_perm(perm, user, project) + for user_obj_perm in project_user_obj_perm_qs.iterator(chunk_size=100): + user = User.objects.get(id=user_obj_perm.user_id) + assign_perm(perm_str, user, project) - for perm in project_group_obj_perm_qs.iterator(chunk_size=100): - group = Group.objects.get(id=perm.group_id) - assign_perm(perm, group, project) + for group_obj_perm in project_group_obj_perm_qs.iterator(chunk_size=100): + group = Group.objects.get(id=group_obj_perm.group_id) + assign_perm(perm_str, group, project) eta -= 1 print("eta", eta) From 2b10d771955beb81d629a0932362a1bfd902c9df Mon Sep 17 00:00:00 2001 From: Kelvin Muchiri Date: Mon, 26 Aug 2024 20:25:54 +0300 Subject: [PATCH 2/2] rename symbol --- .../0023_populate_project_entity_list_perm.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py b/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py index 998f32372e..69f1fc190a 100644 --- a/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py +++ b/onadata/apps/logger/migrations/0023_populate_project_entity_list_perm.py @@ -15,11 +15,11 @@ def add_project_entitylist_perm(apps, schema_editor): """Assign `add_project_entitylist` permission to existing Owners, Managers""" Project = apps.get_model("logger", "Project") content_type = ContentType.objects.get_for_model(Project) - perm_str = "add_project_entitylist" + perm_codename = "add_project_entitylist" with use_master: _, created = Permission.objects.get_or_create( - codename=perm_str, + codename=perm_codename, content_type=content_type, defaults={ "name": "Can add entitylist to project", @@ -27,7 +27,7 @@ def add_project_entitylist_perm(apps, schema_editor): ) if created: - print(f"Permission {perm_str} created because it does not exist") + print(f"Permission {perm_codename} created because it does not exist") project_qs = Project.objects.filter(deleted_at__isnull=True) eta = project_qs.count() @@ -44,11 +44,11 @@ def add_project_entitylist_perm(apps, schema_editor): for user_obj_perm in project_user_obj_perm_qs.iterator(chunk_size=100): user = User.objects.get(id=user_obj_perm.user_id) - assign_perm(perm_str, user, project) + assign_perm(perm_codename, user, project) for group_obj_perm in project_group_obj_perm_qs.iterator(chunk_size=100): group = Group.objects.get(id=group_obj_perm.group_id) - assign_perm(perm_str, group, project) + assign_perm(perm_codename, group, project) eta -= 1 print("eta", eta)