MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / process_inferences

Function process_inferences

vulnerabilities/improve_runner.py:63–168  ·  view source on GitHub ↗

Return number of inferences processed. An atomic transaction that updates both the Advisory (e.g. date_imported) and processes the given inferences to create or update corresponding database fields. This avoids failing the entire improver when only a single inference is err

(
    inferences: List[Inference],
    advisory: Advisory,
    improver_name: str,
)

Source from the content-addressed store, hash-verified

61
62@transaction.atomic
63def process_inferences(
64 inferences: List[Inference],
65 advisory: Advisory,
66 improver_name: str,
67):
68 """
69 Return number of inferences processed.
70 An atomic transaction that updates both the Advisory (e.g. date_imported)
71 and processes the given inferences to create or update corresponding
72 database fields.
73
74 This avoids failing the entire improver when only a single inference is
75 erroneous. Also, the atomic transaction for every advisory and its
76 inferences makes sure that date_imported of advisory is consistent.
77 """
78 inferences_processed_count = 0
79
80 if not inferences:
81 logger.warning(f"Nothing to improve. Source: {improver_name} Advisory id: {advisory.id}")
82 return inferences_processed_count
83
84 logger.info(f"Improving advisory id: {advisory.id}")
85
86 for inference in inferences:
87 vulnerability = get_or_create_vulnerability_and_aliases(
88 vulnerability_id=inference.vulnerability_id,
89 aliases=inference.aliases,
90 summary=inference.summary,
91 advisory=advisory,
92 )
93
94 if not vulnerability:
95 logger.warning(f"Unable to get vulnerability for inference: {inference!r}")
96 continue
97
98 for ref in inference.references:
99
100 reference = VulnerabilityReference.objects.get_or_none(
101 reference_id=ref.reference_id,
102 reference_type=ref.reference_type,
103 url=ref.url,
104 )
105
106 if not reference:
107 reference = create_valid_vulnerability_reference(
108 reference_id=ref.reference_id,
109 reference_type=ref.reference_type,
110 url=ref.url,
111 )
112 if not reference:
113 continue
114
115 VulnerabilityRelatedReference.objects.update_or_create(
116 reference=reference,
117 vulnerability=vulnerability,
118 )
119
120 for severity in ref.severities:

Calls 9

get_or_noneMethod · 0.80
update_or_createMethod · 0.80
addMethod · 0.80
saveMethod · 0.45