@@ -512,6 +512,9 @@ def assign_object(self, obj, user, replace_version=False):
512512 existing_relation = other_assigned_versions [0 ]
513513 other_version_object = getattr (existing_relation , object_model_name )
514514 existing_relation .update (** {object_model_name : obj , "last_modified_by" : user })
515+ # Update the weighted_risk_score from the new related_object
516+ existing_relation .refresh_from_db ()
517+ existing_relation .update_weighted_risk_score ()
515518 message = f'Updated { object_model_name } "{ other_version_object } " to "{ obj } "'
516519 History .log_change (user , self , message )
517520 return "updated" , existing_relation
@@ -864,9 +867,9 @@ def compute_weighted_risk_score(self):
864867 weighted_risk_score = float (risk_score ) * float (exposure_factor )
865868 return weighted_risk_score
866869
867- def set_weighted_risk_score (self ):
870+ def set_weighted_risk_score (self , save = False ):
868871 """
869- Update the `weighted_risk_score` for the current instance.
872+ Set the `weighted_risk_score` for the current instance.
870873
871874 The method computes the weighted risk score using `compute_weighted_risk_score()`
872875 and assigns the computed value to the `weighted_risk_score` field if it differs
@@ -878,6 +881,13 @@ def set_weighted_risk_score(self):
878881 if weighted_risk_score != self .weighted_risk_score :
879882 self .weighted_risk_score = weighted_risk_score
880883
884+ def update_weighted_risk_score (self ):
885+ """Update the `weighted_risk_score` for the current instance."""
886+ weighted_risk_score = self .compute_weighted_risk_score ()
887+ if weighted_risk_score != self .weighted_risk_score :
888+ self .weighted_risk_score = weighted_risk_score
889+ self .raw_update (weighted_risk_score = weighted_risk_score )
890+
881891 def as_spdx (self ):
882892 """
883893 Set the `license_concluded` using the license choice of the relationship,
0 commit comments