@@ -3268,7 +3268,7 @@ def _validate_batch(self, model, batch, validation_errors, required_libraries):
3268
3268
)
3269
3269
3270
3270
def _create_model_objects (self , model , objects , link_dump_database_ids ):
3271
- """Create all objects for a model after validation."""
3271
+ """Create all objects for a model after validation during domain import ."""
3272
3272
logger .debug ("Creating objects for model" , model = model )
3273
3273
3274
3274
model_name = f"{ model ._meta .app_label } .{ model ._meta .model_name } "
@@ -3302,7 +3302,7 @@ def _create_model_objects(self, model, objects, link_dump_database_ids):
3302
3302
)
3303
3303
3304
3304
def _create_batch (self , model , batch , link_dump_database_ids ):
3305
- """Create a batch of objects with proper relationship handling."""
3305
+ """Create a batch of objects with proper relationship handling during domain import ."""
3306
3306
# Create all objects in the batch within a single transaction
3307
3307
with transaction .atomic ():
3308
3308
for obj in batch :
@@ -3363,7 +3363,7 @@ def _process_model_relationships(
3363
3363
link_dump_database_ids ,
3364
3364
many_to_many_map_ids ,
3365
3365
):
3366
- """Process model-specific relationships."""
3366
+ """Process model-specific relationships during domain import ."""
3367
3367
3368
3368
def get_mapped_ids (
3369
3369
ids : List [str ], link_dump_database_ids : Dict [str , str ]
@@ -3410,6 +3410,9 @@ def get_mapped_ids(
3410
3410
many_to_many_map_ids ["evidence_ids" ] = get_mapped_ids (
3411
3411
_fields .pop ("evidences" , []), link_dump_database_ids
3412
3412
)
3413
+ many_to_many_map_ids ["objective_ids" ] = get_mapped_ids (
3414
+ _fields .pop ("objectives" , []), link_dump_database_ids
3415
+ )
3413
3416
ref_control_id = link_dump_database_ids .get (
3414
3417
_fields ["reference_control" ]
3415
3418
)
@@ -3466,6 +3469,9 @@ def get_mapped_ids(
3466
3469
many_to_many_map_ids [map_key ] = get_mapped_ids (
3467
3470
_fields .pop (field , []), link_dump_database_ids
3468
3471
)
3472
+ many_to_many_map_ids ["qualification_ids" ] = get_mapped_ids (
3473
+ _fields .pop ("qualifications" , []), link_dump_database_ids
3474
+ )
3469
3475
3470
3476
case "entity" :
3471
3477
_fields .pop ("owned_folders" , None )
@@ -3576,7 +3582,7 @@ def get_mapped_ids(
3576
3582
return _fields
3577
3583
3578
3584
def _set_many_to_many_relations (self , model , obj , many_to_many_map_ids ):
3579
- """Set many-to-many relationships after object creation."""
3585
+ """Set many-to-many relationships after object creation during domain import ."""
3580
3586
model_name = model ._meta .model_name
3581
3587
3582
3588
match model_name :
@@ -3590,7 +3596,8 @@ def _set_many_to_many_relations(self, model, obj, many_to_many_map_ids):
3590
3596
case "appliedcontrol" :
3591
3597
if evidence_ids := many_to_many_map_ids .get ("evidence_ids" ):
3592
3598
obj .evidences .set (Evidence .objects .filter (id__in = evidence_ids ))
3593
-
3599
+ if "objective_ids" in many_to_many_map_ids :
3600
+ obj .objectives .set (many_to_many_map_ids ["objective_ids" ])
3594
3601
case "requirementassessment" :
3595
3602
if applied_control_ids := many_to_many_map_ids .get ("applied_controls" ):
3596
3603
obj .applied_controls .set (
@@ -3620,6 +3627,7 @@ def _set_many_to_many_relations(self, model, obj, many_to_many_map_ids):
3620
3627
AppliedControl ,
3621
3628
"existing_applied_controls" ,
3622
3629
),
3630
+ "qualification_ids" : (Qualification , "qualifications" ),
3623
3631
}.items ():
3624
3632
if ids := many_to_many_map_ids .get (field ):
3625
3633
getattr (obj , model_class [1 ]).set (
0 commit comments