From 18560e62b7d5c23e09a2317259d31cfa2103d97f Mon Sep 17 00:00:00 2001 From: Cody Maffucci <46459665+Maffooch@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:02:58 -0600 Subject: [PATCH] Async Delete: Race condition bolstering --- dojo/models.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dojo/models.py b/dojo/models.py index 99074a9cf3b..787e2099bbd 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -5,6 +5,7 @@ import os import re import warnings +from contextlib import suppress from datetime import datetime from pathlib import Path from uuid import uuid4 @@ -1575,7 +1576,10 @@ def delete(self, *args, **kwargs): import dojo.finding.helper as helper helper.prepare_duplicates_for_delete(engagement=self) super().delete(*args, **kwargs) - calculate_grade(self.product) + with suppress(Product.DoesNotExist): + # Suppressing a potential issue created from async delete removing + # related objects in a separate task + calculate_grade(self.product) def inherit_tags(self, potentially_existing_tags): # get a copy of the tags to be inherited @@ -2185,7 +2189,10 @@ def hash_code_allows_null_cwe(self): def delete(self, *args, **kwargs): logger.debug("%d test delete", self.id) super().delete(*args, **kwargs) - calculate_grade(self.engagement.product) + with suppress(Engagement.DoesNotExist, Product.DoesNotExist): + # Suppressing a potential issue created from async delete removing + # related objects in a separate task + calculate_grade(self.engagement.product) @property def statistics(self): @@ -2745,7 +2752,10 @@ def delete(self, *args, **kwargs): import dojo.finding.helper as helper helper.finding_delete(self) super().delete(*args, **kwargs) - calculate_grade(self.test.engagement.product) + with suppress(Test.DoesNotExist, Engagement.DoesNotExist, Product.DoesNotExist): + # Suppressing a potential issue created from async delete removing + # related objects in a separate task + calculate_grade(self.test.engagement.product) # only used by bulk risk acceptance api @classmethod