Skip to content

Commit

Permalink
Merge pull request #639 from Hritik14/bugfix
Browse files Browse the repository at this point in the history
Make sure fixed purl is optional in Inference
  • Loading branch information
Hritik14 authored Mar 1, 2022
2 parents 2f9b863 + 80579a5 commit f9f4bc0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions vulnerabilities/improve_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ def process_inferences(inferences: List[Inference], advisory: Advisory, improver
fix=False,
).update_or_create()

fixed_package, _ = _get_or_create_package(inference.fixed_purl)
models.PackageRelatedVulnerability(
vulnerability=vuln,
package=fixed_package,
created_by=improver_name,
confidence=inference.confidence,
fix=True,
).update_or_create()
if inference.fixed_purl:
fixed_package, _ = _get_or_create_package(inference.fixed_purl)
models.PackageRelatedVulnerability(
vulnerability=vuln,
package=fixed_package,
created_by=improver_name,
confidence=inference.confidence,
fix=True,
).update_or_create()

advisory.date_improved = datetime.now(timezone.utc)
advisory.save()
Expand Down
4 changes: 2 additions & 2 deletions vulnerabilities/improver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Inference:
confidence: int = MAX_CONFIDENCE
summary: Optional[str] = None
affected_purls: List[PackageURL] = dataclasses.field(default_factory=list)
fixed_purl: PackageURL = dataclasses.field(default_factory=list)
fixed_purl: PackageURL = None
references: List[Reference] = dataclasses.field(default_factory=list)

def __post_init__(self):
Expand All @@ -49,7 +49,7 @@ def __post_init__(self):

versionless_purls = []
for purl in self.affected_purls + [self.fixed_purl]:
if not purl.version:
if purl and not purl.version:
versionless_purls.append(purl)

assert (
Expand Down

0 comments on commit f9f4bc0

Please sign in to comment.