diff --git a/epictrack-api/src/api/services/work.py b/epictrack-api/src/api/services/work.py index 9fdf14034..b5a623801 100644 --- a/epictrack-api/src/api/services/work.py +++ b/epictrack-api/src/api/services/work.py @@ -816,6 +816,7 @@ def import_first_nations(cls, work_id: int, indigenous_nation_ids: [int]): ).all(), ) ) + existing_first_nations_ids = [nation["indigenous_nation_id"] for nation in existing_first_nations] # Mark removed entries as inactive disabled_count = existing_first_nations_qry.filter( @@ -838,9 +839,12 @@ def import_first_nations(cls, work_id: int, indigenous_nation_ids: [int]): work = Work.find_by_id(work_id) nations_in_same_project = find_all_by_project_id(work.project_id) + + new_nations_ids = [nation_id for nation_id in indigenous_nation_ids + if nation_id not in existing_first_nations_ids] selected_nations = [ nation for nation in nations_in_same_project - if nation.indigenous_nation_id in indigenous_nation_ids + if nation.indigenous_nation_id in new_nations_ids ] nations_to_insert = [ {