diff --git a/backend/core/helpers.py b/backend/core/helpers.py index daec326d5..9653d254c 100644 --- a/backend/core/helpers.py +++ b/backend/core/helpers.py @@ -1182,7 +1182,6 @@ def duplicate_related_objects( duplicate_object: models.Model, target_folder: Folder, field_name: str, - model_class: Type[models.Model], ): """ Duplicates related objects from a source object to a duplicate object, avoiding duplicates in the target folder. @@ -1190,9 +1189,8 @@ def duplicate_related_objects( Parameters: - source_object (object): The source object containing related objects to duplicate. - duplicate_object (object): The object where duplicated objects will be linked. - - target_folder (object): The folder where duplicated objects will be stored. - - field_name (str): The field name representing the related objects in the source object. - - model_class (type): The model class of the related objects. + - target_folder (Folder): The folder where duplicated objects will be stored. + - field_name (str): The field name representing the related objects in the source """ def process_related_object( @@ -1248,6 +1246,8 @@ def duplicate_and_link_object(new_obj, duplicate_object, target_folder, field_na new_obj.save() link_existing_object(duplicate_object, new_obj, field_name) + model_class = getattr(type(source_object), field_name).field.related_model + # Get parent and sub-folders of the target folder target_parent_folders = target_folder.get_parent_folders() sub_folders = target_folder.sub_folders() diff --git a/backend/core/views.py b/backend/core/views.py index b869938cd..07a48ed1d 100644 --- a/backend/core/views.py +++ b/backend/core/views.py @@ -641,21 +641,18 @@ def duplicate(self, request, pk): duplicate_scenario, duplicate_risk_assessment.project.folder, "applied_controls", - AppliedControl, ) duplicate_related_objects( scenario, duplicate_scenario, duplicate_risk_assessment.project.folder, "threats", - Threat, ) duplicate_related_objects( scenario, duplicate_scenario, duplicate_risk_assessment.project.folder, "assets", - Asset, ) if (