Skip to content

Commit

Permalink
Merge pull request #1542 from aboutcode-org/1541-fix-importer-crash
Browse files Browse the repository at this point in the history
Fix importer crash #1541
  • Loading branch information
TG1999 authored Aug 16, 2024
2 parents cb38a58 + d567bb0 commit b7a7237
Show file tree
Hide file tree
Showing 6 changed files with 1,238 additions and 300 deletions.
42 changes: 27 additions & 15 deletions vulnerabilities/import_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,23 @@ def do_import(self, advisories) -> None:
if advisory.date_imported:
continue
logger.info(f"Processing advisory: {advisory!r}")
advisory_data = None
inferences = None
try:
inferences = advisory_importer.get_inferences(
advisory_data=advisory.to_advisory_data()
)
advisory_data = advisory.to_advisory_data()
inferences = advisory_importer.get_inferences(advisory_data=advisory_data)
process_inferences(
inferences=inferences,
advisory=advisory,
improver_name=importer_name,
)
except Exception as e:
logger.info(f"Failed to process advisory: {advisory!r} with error {e!r}")
except Exception:
from pprint import pformat

logger.warning(
f"Failed to process advisory:\n{pformat(advisory_data.to_dict())}\n\n"
f"with error:\n{traceback_format_exc()}\n\n"
)
logger.info("Finished importing using %s.", advisory_importer.__class__.qualified_name)

def process_advisories(
Expand Down Expand Up @@ -181,17 +187,23 @@ def process_inferences(inferences: List[Inference], advisory: Advisory, improver
reference=reference,
vulnerability=vulnerability,
)

updated = False
for severity in ref.severities:
_vs, updated = VulnerabilitySeverity.objects.update_or_create(
scoring_system=severity.system.identifier,
reference=reference,
defaults={
"value": str(severity.value),
"scoring_elements": str(severity.scoring_elements),
"published_at": str(severity.published_at),
},
)
try:
published_at = str(severity.published_at) if severity.published_at else None
_vs, updated = VulnerabilitySeverity.objects.update_or_create(
scoring_system=severity.system.identifier,
reference=reference,
defaults={
"value": str(severity.value),
"scoring_elements": str(severity.scoring_elements),
"published_at": published_at,
},
)
except:
logger.error(
f"Failed to create VulnerabilitySeverity for: {severity} with error:\n{traceback_format_exc()}"
)
if updated:
logger.info(
f"Severity updated for reference {ref!r} to value: {severity.value!r} "
Expand Down
Loading

0 comments on commit b7a7237

Please sign in to comment.