Skip to content

Commit c70ac81

Browse files
committed
rework the implementation
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent ebf9ca1 commit c70ac81

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

product_portfolio/importers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,16 @@ def import_vulnerability(vulnerability_data, product_package):
839839
is_reachable = False
840840

841841
if is_reachable is not None:
842-
VulnerabilityAnalysis.objects.filter(
842+
analysis, created = VulnerabilityAnalysis.objects.get_or_create(
843843
product_package=product_package,
844844
vulnerability=vulnerability,
845-
is_reachable__isnull=True,
846-
).update(is_reachable=is_reachable)
845+
dataspace=product_package.dataspace,
846+
defaults={"is_reachable": is_reachable},
847+
)
848+
if not created and analysis.is_reachable is None:
849+
VulnerabilityAnalysis.objects.filter(pk=analysis.pk).update(
850+
is_reachable=is_reachable
851+
)
847852

848853
def import_package(self, package_data):
849854
# Vulnerabilities are assigned after the package creation.

vulnerabilities/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,9 @@ class Meta:
584584
def __str__(self):
585585
return f"{self.vulnerability} analysis"
586586

587+
def has_content_fields(self):
588+
return super().has_content_fields() or self.is_reachable is not None
589+
587590
def save(self, *args, **kwargs):
588591
"""Set the product and package fields values from the product_package FK."""
589592
self.product_id = self.product_package.product_id

0 commit comments

Comments
 (0)