Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix importer crash #1541 #1542

Merged
merged 4 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pombredanne Would it be better to move the pprint library import to the top of the code?


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
Loading